[16467] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3879 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 2 06:05:36 2000

Date: Wed, 2 Aug 2000 03:05:21 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965210721-v9-i3879@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 2 Aug 2000     Volume: 9 Number: 3879

Today's topics:
        Algorithm for efficient creation of unique, random arra <phill@modulus.com.au>
    Re: APACHE Login name <glodalec@yahoo.com>
    Re: APACHE Login name <gellyfish@gellyfish.com>
        attribute names in errors in DBI:mysql <pjl-news@barefooters.org>
    Re: Breaking up strings into arbitrary lengths (Keith Calvert Ivey)
    Re: Breaking up strings into arbitrary lengths (Gwyn Judd)
    Re: Breaking up strings into arbitrary lengths (Logan Shaw)
    Re: Breaking up strings into arbitrary lengths (Abigail)
    Re: Breaking up strings into arbitrary lengths <lr@hpl.hp.com>
    Re: Broadcast-IP-address or netmask <gellyfish@gellyfish.com>
        Changing a user password <tschilbach@aodinc.com>
    Re: check if $sth->fetch is empty <gellyfish@gellyfish.com>
    Re: Configure Win32::ODBC Connection to a SQL Server? <cbegemann@orga.com>
    Re: day_of_week() and age() without using Date::Calc ? madsere@my-deja.com
    Re: day_of_week() and age() without using Date::Calc ? <sb@muccpu1.muc.sdm.de>
    Re: day_of_week() and age() without using Date::Calc ? <bart.lateur@skynet.be>
    Re: day_of_week() and age() without using Date::Calc ? <guenther.degenfelder@datev.de>
    Re: DBI:: UPDATE format (Perl DBI O'Reilly fails to exp <debjit@oyeindia.com>
    Re: Detecting end of HTTP reply (Villy Kruse)
    Re: dialing from another computer <spam@whoville.com>
        Disregard! was(Algorithm for efficient creation of uniq <phill@modulus.com.au>
    Re: Documentation? WIN32 ODBC: Access97 - ActiveState P <gellyfish@gellyfish.com>
    Re: Dynamic String to hash <bart.lateur@skynet.be>
        Excessive memory use under OSF1 (was: numeric storage e <iltzu@sci.invalid>
        formating output <buggerm@de.ibm.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 02 Aug 2000 17:59:12 +1000
From: Peter Hill <phill@modulus.com.au>
Subject: Algorithm for efficient creation of unique, random array
Message-Id: <3987D4D0.6796@modulus.com.au>

Salutations!
I need to efficiently select 'x' unique, random (or pseudo-random)
numbers from 'y' options, where 'y' is the range 0..y.
What I've done so far is inefficient:

	sub randomUniqueSelect{
		my ($howMany, $fromHowMany) = @_;
		my @result = ();
		my %done = ();
		while (@result < $howMany){
			my $select = int(rand($fromHowMany));
			if (! $done{$select}){
				push(@result,$select);
				$done{$select} = 1;
			}
		}
		return @result;
	}

The problem is that it might take a large number of iterations to
populate the array, as the random selection process can return the same
number an indefinite but potentially large number of times. I've already
seen it loop 9 times in response to randomUniqueSelect(4,4);

I'm sure there is an efficient algorithm for this, it just is not
obvious to me.
TIA
-- 
Peter Hill,
Modulus Pty. Ltd.,
http://www.modulus.com.au/


------------------------------

Date: Wed, 02 Aug 2000 06:46:29 +0200
From: Mouse <glodalec@yahoo.com>
Subject: Re: APACHE Login name
Message-Id: <3987A7A5.49B3@yahoo.com>

nobull@mail.com wrote:
> 
> Mouse <glodalec@yahoo.com> writes:
> 
> > both of commands (remote_user(),user_name()) returns empty
> > string, even when I am logged thru apache authorization.
> 
> Are you sure?  Is it perhaps possible that the CGI script is located
> in a directory that's not password resticted?
> 
> --
>      \\   ( )
>   .  _\\__[oo
>  .__/  \\ /\@
>  .  l___\\
>   # ll  l\\
>  ###LL  LL\\
Hi Again !

The situation is like this.

I have this kind of directory structure.

home_www/cgi-bin
home_www/sys    <------------- password protected in Apache access.conf
home_www/sys/system1
home_www/sys/system2
home_www/sys/system3
home_www/doc


My PERL script takes one parameter:

LOG.pl?sys=system1

Now I have information, about which system user will observe, so I need
his name as well.
Directories under /sys are not anymore under authorization (I think
there is no need to be, since main /sys directory already is). Tell me
please, if I'm wrong.

Regards


------------------------------

Date: Wed, 02 Aug 2000 08:50:15 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: APACHE Login name
Message-Id: <bhRh5.874$82.45377@news.dircon.co.uk>

On Wed, 02 Aug 2000 06:46:29 +0200, Mouse Wrote:
> nobull@mail.com wrote:
>> 
>> Mouse <glodalec@yahoo.com> writes:
>> 
>> > both of commands (remote_user(),user_name()) returns empty
>> > string, even when I am logged thru apache authorization.
>> 
>> Are you sure?  Is it perhaps possible that the CGI script is located
>> in a directory that's not password resticted?
> 
> The situation is like this.
> 
> I have this kind of directory structure.
> 
> home_www/cgi-bin
> home_www/sys    <------------- password protected in Apache access.conf
> home_www/sys/system1
> home_www/sys/system2
> home_www/sys/system3
> home_www/doc
> 
> 
> My PERL script takes one parameter:
> 
> LOG.pl?sys=system1
> 
> Now I have information, about which system user will observe, so I need
> his name as well.
> Directories under /sys are not anymore under authorization (I think
> there is no need to be, since main /sys directory already is). Tell me
> please, if I'm wrong.
> 

So your program in /cgi-bin is not protected so it will not get the 
credentials - please ask in comp.infosystems.www.servers.ms-windows as I
suggested before becuase this is an apache configuration issue and nothing
whatsoever to do with Perl.

/J\


------------------------------

Date: 2 Aug 2000 07:52:24 GMT
From: "Paul J. Lucas" <pjl-news@barefooters.org>
Subject: attribute names in errors in DBI:mysql
Message-Id: <8m8jvo$1vrf$1@nntp1.ba.best.com>

	I'm using MySQL for a database.  In a given table, there is a
	UNIQUE constraint on an attribute.  Inserting a duplicate value
	for said attribute righty causes an error; however, the error is
	of the form:

		Duplicate '<value>' for key 3

	where <value> is the duplicate value.  The problem is that this
	error message, as-is, can not be shown to an end user.  What I
	want is to print the attribute name and not its index, i.e.:

		Duplicate '<value>' for "login"

	There appears to be no way to set this in DBI or DBD:mysql
	(unless I've missed it).  What can be done is to do a:

		SHOW COLUMNS FROM <table>

	and then read the column information into an array then use the
	index (-1) as an index into the array to get the attribute name.
	However, this is really awkward.

	Is there a better way to get human-readable errors from MySQL
	via DBI/DBD?

	- Paul


------------------------------

Date: Wed, 02 Aug 2000 03:58:41 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Breaking up strings into arbitrary lengths
Message-Id: <398a9a69.7797493@news.newsguy.com>

Paul King <pking@idirect.com> wrote:

>sub cutupline {
>   # Accepts a string as input
>   # Returns an array of strings which are of length 3 kilobytes or
>less.
>   # Syntax: @new_array = &cutupline $string;
>   #
>   # It seems that someone didn't think about breaking up a string
>   # on arbitrary byte boundaries. Most of Perl's efforts have been to
>   # break up strings by their pattern. This is probably going to be
>slow.
[snip]

You're right it's incredibly slow, but that's not Perl's fault.
Others have suggested using substr() or unpack().  You could
also use a regex:

    sub cutupline {
        my $string = shift;
        my @chunks = $string =~ /.{1,3072}/gs;
    }

Any of those three will give you a subroutine much, much smaller
and much, much faster than yours.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


------------------------------

Date: Wed, 02 Aug 2000 04:52:35 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Breaking up strings into arbitrary lengths
Message-Id: <slrn8ofa8h.811.tjla@thislove.dyndns.org>

I was shocked! How could Godzilla! <godzilla@stomp.stomp.tokyo>
say such a terrible thing:
>Why not use a while length greater than 3072, 
>substring and grab 3072 characters then close
>out your while by grabbing whatever is left over,
>after iteration, with each substring grab and your
>final remainder being pushed into an array?

This reply was helpful, concise and correct. Is there something wrong?
Are you feeling okay?

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The most incomprehensible thing about the world is that it is comprehensible.					-- Albert Einstein


------------------------------

Date: 2 Aug 2000 00:41:14 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Breaking up strings into arbitrary lengths
Message-Id: <8m8c9q$d2h$1@provolone.cs.utexas.edu>

In article <398a9a69.7797493@news.newsguy.com>,
Keith Calvert Ivey <kcivey@cpcug.org> wrote:
>Paul King <pking@idirect.com> wrote:
>
>>sub cutupline {
>>   # Accepts a string as input
>>   # Returns an array of strings which are of length 3 kilobytes or
>>less.
>>   # Syntax: @new_array = &cutupline $string;
>>   #
>>   # It seems that someone didn't think about breaking up a string
>>   # on arbitrary byte boundaries. Most of Perl's efforts have been to
>>   # break up strings by their pattern. This is probably going to be
>>slow.
>[snip]
>
>You're right it's incredibly slow, but that's not Perl's fault.
>Others have suggested using substr() or unpack().  You could
>also use a regex:
>
>    sub cutupline {
>        my $string = shift;
>        my @chunks = $string =~ /.{1,3072}/gs;
>    }

True.  Parenthesis would help, though:

	my @chunks = $string =~ /(.{1,3072})/gs;

Also, you could just return the match directly without using a
temporary variable:

	sub cutupline3072
		{
		my $string = shift;
		return ($string =~ /(.{1,3072})/gs);
		}

  - Logan


------------------------------

Date: 02 Aug 2000 06:57:52 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Breaking up strings into arbitrary lengths
Message-Id: <slrn8ofhj2.vcg.abigail@alexandra.foad.org>

Logan Shaw (logan@cs.utexas.edu) wrote on MMDXXVIII September MCMXCIII in
<URL:news:8m8c9q$d2h$1@provolone.cs.utexas.edu>:
## 
## Also, you could just return the match directly without using a
## temporary variable:
## 
## 	sub cutupline3072
## 		{
## 		my $string = shift;
## 		return ($string =~ /(.{1,3072})/gs);
## 		}


And $string is permanent?

    sub cutupline3072 {shift =~ /.{1,3072}/gs}


Or:

    sub AUTOLOAD {shift =~ /.{1,$1}/gs if $AUTOLOAD =~ /::cutupline([1-9]\d*)$/}



Abigail
-- 
print v74.117.115.116.32, v97.110.111.116.104.101.114.32,
      v80.101.114.108.32, v72.97.99.107.101.114.10;


------------------------------

Date: Wed, 2 Aug 2000 00:08:29 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Breaking up strings into arbitrary lengths
Message-Id: <MPG.13f168cb3d661e5298ac24@nntp.hpl.hp.com>

In article <8m8c9q$d2h$1@provolone.cs.utexas.edu>, logan@cs.utexas.edu 
says...
> In article <398a9a69.7797493@news.newsguy.com>,
> Keith Calvert Ivey <kcivey@cpcug.org> wrote:

 ...

> >You're right it's incredibly slow, but that's not Perl's fault.
> >Others have suggested using substr() or unpack().  You could
> >also use a regex:
> >
> >    sub cutupline {
> >        my $string = shift;
> >        my @chunks = $string =~ /.{1,3072}/gs;
> >    }
> 
> True.  Parenthesis would help, though:
> 
> 	my @chunks = $string =~ /(.{1,3072})/gs;

They might help you understand, but they are unnecessary.  As you could 
have discovered had you bothered to test the code both ways -- with and 
without the capturing parentheses -- before posting your observation. 

> Also, you could just return the match directly without using a
> temporary variable:
> 
> 	sub cutupline3072
> 		{
> 		my $string = shift;
> 		return ($string =~ /(.{1,3072})/gs);
> 		}

But, as Ilja Tabachnik observed, it is better to return a reference than 
to copy all those data unnecessarily.  So, as a one-line subroutine:

  sub cutupline3072 { [ $_[0] =~ /.{1,3072}/gs ] }

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 2 Aug 2000 00:16:48 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Broadcast-IP-address or netmask
Message-Id: <8m7lp0$vee$1@orpheus.gellyfish.com>

On Tue, 1 Aug 2000 18:16:19 +0200 Ralf Kible wrote:
> I'm looking for a possibility to find the broadcast-address or netmask of an
> network-interface, because I try to send a broadcast-message via UDP.

There may be a module at CPAN <http://www.cpan.org> that will help.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


------------------------------

Date: Wed, 2 Aug 2000 00:46:18 -0500
From: "Timothy H. Schilbach" <tschilbach@aodinc.com>
Subject: Changing a user password
Message-Id: <8m8cj6$ngu$1@news.chatlink.com>

Hello,

There is a unique problem with UserChangePassword. I have written a CGI
script that will change a users password on the domain. This works great.
Now I can log on as the new password.

Now the problem. After I change the password with the online password
changer. I am able to log onto my domain from any computer using the NEW or
OLD password. How is this possible? How can I make sure that the old
password is destroyed? PLEASE HELP!!!!

I have included my code below:
--------------------------------------
#!/usr/local/bin/perl
&GetFormInput;
$username = $field{'username'} ;
$oldpassword = $field{'oldpassword'} ;
$newpassword = $field{'newpassword'} ;
$B1 = $field{'B1'} ;
$B2 = $field{'B2'} ;

sub GetFormInput {

 (*fval) = @_ if @_ ;

 local ($buf);
 if ($ENV{'REQUEST_METHOD'} eq 'POST') {
  read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
 }
 else {
  $buf=$ENV{'QUERY_STRING'};
 }
 if ($buf eq "") {
   return 0 ;
  }
 else {
   @fval=split(/&/,$buf);
  foreach $i (0 .. $#fval){
   ($name,$val)=split (/=/,$fval[$i],2);
   $val=~tr/+/ /;
   $val=~ s/%(..)/pack("c",hex($1))/ge;
   $name=~tr/+/ /;
   $name=~ s/%(..)/pack("c",hex($1))/ge;

   if (!defined($field{$name})) {
    $field{$name}=$val;
   }
   else {
    $field{$name} .= ",$val";

    #if you want multi-selects to goto into an array change to:
    #$field{$name} .= "\0$val";
   }


     }
  }
return 1;
}

use Win32::AdminMisc;

if (Win32::AdminMisc::UserChangePassword("xxxxx",   #this is a fake domain
                                         "$username",
                                         "$oldpassword",
                                         "$newpassword")){
    print "Password successfully changed\n";
}else{
    print "Password failed to change.\n";
}


--
Timothy H. Schilbach
Alpha Omega Design Inc.
tschilbach@aodinc.com
1-877-263-7094
Visit our website at www.aodinc.com

Highspeed internet connectivity and web hosting services








------------------------------

Date: 2 Aug 2000 09:05:47 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: check if $sth->fetch is empty
Message-Id: <8m8kor$tfj$1@orpheus.gellyfish.com>

On Tue, 01 Aug 2000 16:03:02 GMT Rafael Garcia-Suarez wrote:
> vnguyen_1999@my-deja.com wrote in comp.lang.perl.misc:
>>Hello !!!
>>
>>How can I check if $sth->fetch is empty?
> 
>   my $row = $sth->fetch;
>   if (defined $row) {
>     print "empty\n" if $#$row == -1;
>     print "empty\n" unless @$row;
>     print "empty\n" if not defined $row->[0];
>     # ... TMTOWTDI
>   } else {
>     die "$DBI::errstr\n";
>   }
> 

Except not returning any rows is not an error in itself so $DBI::errstr 
is likely to be undefined in most cases here.  With DBD::Informix one
might do :

if ( defined $row )
{
  # whatever
}
else
{
  if ( $sth->{ix_sqlcode} == 100 )
  {
    # Query resulted in no rows normally
  }
  else
  {
    # Some abnormal condition
    print $DBI::errstr;
  }
}

Most DBD drivers will supply similar access to the status codes of the
engine.

Of course if some error had occurred then one would probably have caught
it at the execute() anyhow ...

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


------------------------------

Date: Wed, 2 Aug 2000 09:56:25 +0200
From: "Carola Begemann" <cbegemann@orga.com>
Subject: Re: Configure Win32::ODBC Connection to a SQL Server?
Message-Id: <8m8kf1$ftl$1@relay1.orga.com>

Hello ,
Eyal Ben-David suggested to create the data source manually and then look in
the registy for Details.
It turned out that I had all attributes except
"Driver=C:\WINNT\System32\sqlsrv32.dll " in my list.
So I tried:


  Win32::ODBC::ConfigDSN(ODBC_ADD_SYS_DSN,"SQL Server",
     ( "DSN=$dsn","Description= $condb automatisch generiert",
         "Driver=C:\\WINNT\\System32\\sqlsrv32.dll",
  "Server=$server","Database=$condb", "UID=$user", "PWD=$passwd")

Result still the same , even without the C: or with single \  and ( or) '
for " .
Ieven tried  the path in UNIX  like fashion with correct uppercase and
lowercase letters taken from the path shown in the NT explorer
I still  get the error : No such file or directory
 puzzeled

Maybe I have to create the Connections manually, (not so nice , but works at
least)
Thanks
    Carola




------------------------------

Date: Wed, 02 Aug 2000 06:28:45 GMT
From: madsere@my-deja.com
Subject: Re: day_of_week() and age() without using Date::Calc ?
Message-Id: <8m8f2q$6f9$1@nnrp1.deja.com>

In article <dennis_marti-10F9E7.22533529072000@news.starpower.net>,
  Dennis Marti <dennis_marti@yahoo.com> wrote:
> In article <8lugnm$78s$1@nnrp1.deja.com>, madsere@my-deja.com wrote:
>
> > In article <8lj1d0$pmp$1@nnrp1.deja.com>,
> >   madsere@my-deja.com wrote:
> > > I am frantically looking for two functions:
> > >
> > > 1) One that can return the day-of-week for a given date
> > > 2) one that can return the age for a given date (birthday)
> > >
> > > Yeah I know - Date::Calc can do it.
> > >
> > > Unfortunately my web hosting service doesn't have it installed
and is
> > > not very quick in installing new modules - to say the least.
> >
> > Hmm, nobody knows?  really?
>
> use lib 'Macintosh HD:Desktop Folder:DateManip-5.39';
> use Manip;
>
> $TZ = "UTC";
> $now = Date::Manip::ParseDate( "today" );
> $born = Date::Manip::ParseDate( "10/25/1995" );
> $err = "";
> $delta = Date::Manip::DateCalc( $born, $now, \$err, 1 );
>
> print  "$now - $born == $delta\n";
>
> __END__
>
> prints out
> 2000072922:41:13 - 1995102500:00:00 == +4:9:0:4:22:41:13
>
> The Date::Manip module by Sullivan Beck (on CPAN) can be used from
> whatever directory you feel like putting it in. You don't need to
wait
> for the admin to install it.


Thanks, that does the trick (at a cost though - 6000+ lines of perl -
ouch :-)




Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: 2 Aug 2000 07:55:24 GMT
From: Steffen Beyer <sb@muccpu1.muc.sdm.de>
Subject: Re: day_of_week() and age() without using Date::Calc ?
Message-Id: <8m8k5c$adk$1@solti3.sdm.de>

In article <8m8f2q$6f9$1@nnrp1.deja.com>, madsere@my-deja.com wrote:

[Installing Date::Manip locally]

> Thanks, that does the trick (at a cost though - 6000+ lines of perl -
> ouch :-)

There is also a plain Perl version of Date::Calc, which is much smaller
and faster than that.

See perldoc perlmodinstall for how to install modules locally into your
home directory and the usual places (CPAN/modules/by-module/Date/) for
Date::Pcalc.

Regards,
-- 
    Steffen Beyer <sb@engelschall.com>
    http://www.engelschall.com/u/sb/whoami/ (Who am I)
    http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
    http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)


------------------------------

Date: Wed, 02 Aug 2000 09:31:37 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: day_of_week() and age() without using Date::Calc ?
Message-Id: <98qfossup4ga5nb8ob6b4696q9qcrarb5m@4ax.com>

madsere@my-deja.com wrote:

>Hmm, nobody knows?  really?

I don't know why you post that, 4 days after I poosted my reply.

You can EASILY build your own, using the standard module Time::Local,
and some home made parsing. Not 6000 lines of code, but 10, at most.

As an example: This will tell you the day-of-week of, for example,
today:

	use Time::Local;
	$time = timegm(0, 0, 0, 2, 8-1, 2000);
	$dow = (gmtime($time))[6];
	@dow = qw(Sunday Monday Tuesday Wednesday Thursday Friday
Saturday);
	print "August 2 is a $dow[$dow].\n";
-->
	August 2 is a Wednesday.

-- 
	Bart.


------------------------------

Date: Wed, 2 Aug 2000 11:24:56 +0200
From: "Guenther Degenfelder" <guenther.degenfelder@datev.de>
Subject: Re: day_of_week() and age() without using Date::Calc ?
Message-Id: <3987e880$1@news.datev.de>


<madsere@my-deja.com> schrieb im Newsbeitrag
news:8m8f2q$6f9$1@nnrp1.deja.com...
> In article <dennis_marti-10F9E7.22533529072000@news.starpower.net>,
>   Dennis Marti <dennis_marti@yahoo.com> wrote:
> > In article <8lugnm$78s$1@nnrp1.deja.com>, madsere@my-deja.com wrote:
> >
> > > In article <8lj1d0$pmp$1@nnrp1.deja.com>,
> > >   madsere@my-deja.com wrote:
> > > > I am frantically looking for two functions:
> > > >
> > > > 1) One that can return the day-of-week for a given date
> > > > 2) one that can return the age for a given date (birthday)
> > > >
> > > > Yeah I know - Date::Calc can do it.
> > > >
> > > > Unfortunately my web hosting service doesn't have it installed
> and is
> > > > not very quick in installing new modules - to say the least.
> > >
> > > Hmm, nobody knows?  really?
> >
> > use lib 'Macintosh HD:Desktop Folder:DateManip-5.39';
> > use Manip;
> >
> > $TZ = "UTC";
> > $now = Date::Manip::ParseDate( "today" );
> > $born = Date::Manip::ParseDate( "10/25/1995" );
> > $err = "";
> > $delta = Date::Manip::DateCalc( $born, $now, \$err, 1 );
> >
> > print  "$now - $born == $delta\n";
> >
> > __END__
> >
> > prints out
> > 2000072922:41:13 - 1995102500:00:00 == +4:9:0:4:22:41:13
> >
> > The Date::Manip module by Sullivan Beck (on CPAN) can be used from
> > whatever directory you feel like putting it in. You don't need to
> wait
> > for the admin to install it.
>
>
> Thanks, that does the trick (at a cost though - 6000+ lines of perl -
> ouch :-)
>
>
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

Try this, if you like to count the lines of code:

@TageBisErsten=(
 0,
 31,
 31+28,
 31+28+31,
 31+28+31+30,
 31+28+31+30+31,
 31+28+31+30+31+30,
 31+28+31+30+31+30+31,
 31+28+31+30+31+30+31+31,
 31+28+31+30+31+30+31+31+30,
 31+28+31+30+31+30+31+31+30+31,
 31+28+31+30+31+30+31+31+30+31+30,
 31+28+31+30+31+30+31+31+30+31+30+31
);

sub Schaltjahr
{
 local($jahr)=@_[0];

        return($jahr%4==0 && $jahr%100!=0 || $jahr%400==0);
}

sub TageImJahr
{
 local($tag,$monat,$jahr)=@_;

 return(
  @TageBisErsten[$monat-1]
  +$tag
  +((&Schaltjahr($jahr) && $monat>2) ? (1):(0))
 );
}

sub TageSeitEins
{
 local($tag,$monat,$jahr)=@_;

 return(
  &TageImJahr($tag,$monat,$jahr)
  +($jahr-1)*365
  +int(($jahr-1)/4)
  -int(($jahr-1)/100)
  +int(($jahr-1)/400)
 );
}

sub Wochentag
{
 local($tag,$monat,$jahr)=@_;

 return(
  TageSeitEins($tag,$monat,$jahr) % 7
 );
}

The function TageSeitEins($day,$month,$year) will tell you the number of
days since 1.1.1.
The function Wochentag($day,$month,$year) will tell you the weekday as a
number (0=Sunday, 1=Monday , ...)

Be shure to use four digits for the year (for today the right value is
730333)!!!

Hope this helps!

PS:
Sorry about the german code...    :-]




------------------------------

Date: Wed, 2 Aug 2000 11:01:36 +0530
From: "Debjit" <debjit@oyeindia.com>
Subject: Re: DBI:: UPDATE format (Perl DBI O'Reilly fails to explain properly)
Message-Id: <8m9gia$hcv$1@news.vsnl.net.in>

>> $sth = $dbh->prepare("UPDATE counter FROM wizSearches SET
field_name='$new_value' WHERE ID =...






------------------------------

Date: 2 Aug 2000 08:44:53 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Detecting end of HTTP reply
Message-Id: <slrn8ofns5.j9l.vek@pharmnl.ohout.pharmapartners.nl>

On Tue, 01 Aug 2000 20:17:49 +0100, Tim Cockle <T.Cockle@staffs.ac.uk> wrote:
>Hi,
>
>I am writing a simple proxy.
>
>But I don't seam to be able to detect the end of a HTTP reply.
>
>All the examples I have looked at say to use:
>while (<$server>)...
>To continue to read until the end... But this does not seam to work!
>All that happens is that the proxy continues to try and read until the
>server kills the connection.
>



The updated http protocol alows the server to re-use the connection
if it can agree with the client.  In that case you have to read the
number of bytes as specified in the http header sent by the server.

To complicate maters there is also the chuncked transfer encoding 
which will also uniquely specify the end of the transfer without the
help of EOF.

The details of this is not exactly a perl issue, except to ask if the
LWP package will take care of this detail transparently.



Villy


------------------------------

Date: Wed, 02 Aug 2000 04:13:53 GMT
From: "Grinch" <spam@whoville.com>
Subject: Re: dialing from another computer
Message-Id: <5eNh5.733$pu4.81044@typhoon.ne.mediaone.net>

In article <soen09qfdbm101@corp.supernews.com>, "Hugh Brian"
<hugh.brian@uengineer.com> wrote:

> I want to use a perl script to do this.

It's still not a Perl question. Your question was "which foo.exe do I call
to do x," and the answer is the same, whether you're using a Perl script,
a batch file, or a compiled binary. It's not a question about Perl, it's a
question about foo.exe.

If you've decided which "foo.exe" to use, but don't know how to use it
from a Perl script, then that _is_ a Perl question.

grinch



------------------------------

Date: Wed, 02 Aug 2000 18:19:13 +1000
From: Peter Hill <phill@modulus.com.au>
Subject: Disregard! was(Algorithm for efficient creation of unique, random array)
Message-Id: <3987D981.744D@modulus.com.au>

Peter Hill wrote:
> 
> Salutations!
> I need to efficiently select 'x' unique, random (or pseudo-random)
> numbers from 'y' options, where 'y' is the range 0..y.
> What I've done so far is inefficient:
> 
>         sub randomUniqueSelect{
>                 my ($howMany, $fromHowMany) = @_;
>                 my @result = ();
>                 my %done = ();
>                 while (@result < $howMany){
>                         my $select = int(rand($fromHowMany));
>                         if (! $done{$select}){
>                                 push(@result,$select);
>                                 $done{$select} = 1;
>                         }
>                 }
>                 return @result;
>         }
> 
> The problem is that it might take a large number of iterations to
> populate the array, as the random selection process can return the same
> number an indefinite but potentially large number of times. I've already
> seen it loop 9 times in response to randomUniqueSelect(4,4);
> 
> I'm sure there is an efficient algorithm for this, it just is not
> obvious to me.
> TIA
> --
> Peter Hill,
> Modulus Pty. Ltd.,
> http://www.modulus.com.au/

Aaargh! it's a FAQ! A fisher-yates FAQ!
-- 
Peter Hill,
Modulus Pty. Ltd.,
http://www.modulus.com.au/


------------------------------

Date: 2 Aug 2000 09:35:33 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Documentation? WIN32 ODBC: Access97 - ActiveState Perl script
Message-Id: <8m8mgl$3ii$1@orpheus.gellyfish.com>

On Tue, 01 Aug 2000 15:18:29 +0200 John Øllgård Jensen wrote:
> HI,
> 
> Using Access97 + ActivePerl vers 5 build 522:
> 
> Where do I find some documentation about ODBC naming rules?
> 

I would ask in the newsgroup comp.databases.ms-access as there is nothing
Perl specific about this.

/J\
-- 
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


------------------------------

Date: Wed, 02 Aug 2000 09:05:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Dynamic String to hash
Message-Id: <k9nfosc37oj78q7t8mr0hacgvtdualnuqv@4ax.com>

Ken Hare wrote:

>I have a delimited string
>
>QtyþPart
>NoþSKUþNameþWgtþColorþSizeþoption1þOption2þCustomþNoTaxþPriceþTotalÿ1þPN
>1þSKU1þClassic Teddy
>Bearþ1þGreenþsþoption1þoption2þþ0þ$9.00þ$9.00ÿ1þþ30987þScary
>Dollþþþþþþþ0þ$35.00þ$35.00
>
>Where each item is separated by "ÿ" and each items specs are
>separated by "þ"

Ignoring the word wrap (I assume it's all one line), it sounds to me
like a plain and simple character delimited text file (some people may
not like me using this term), with column headers, and with returns
replaced by "ÿ". Set $/ to "ÿ", and you can read it item by item.

>This string is generated by a compiled shopping cart app so I can't
>modify the code directly to customize output.

Oh well. Is it a string, or a file? I'll assume it's a file.

>I have been trying to modify the string so that It consists of only 5
>fields with the "extra" fields being concatenated into one of the 5
>fields. What complicates this is that the field names can vary
>depending on what product is selected. 
>
>I know that I will need: Qty, SKU, Name, NoTax and Price with all of
>the other fields added in any order to the end of Name.
>
>My strategy up to this point is to take the raw string and split it on
>the item delimiter and dump it into an array. Then take the array and
>somehow cram it into a hash using the first items "specs" (field names)
>as the keys and then supsequent item "specs" as columns. Then somehow
>iterate through this hash and build the new product string the way I
>want.

Well, I've been doing stuff like that quite a lot, and I've developped
several strategies. If you want an array of hashes, this is what you'll
get. I will assume that you read the data from a file, i.e. line by
line. Between us, I'm a bit proud of the elegance of this code...

	$/ = "ÿ";
	$_ = <DATA>; # headers;
	chomp;
	my @header = split /þ/;
	while(<DATA>) {
	    chomp;
	    my %data;
	    @data{@header} = split /þ/;
	    push @record, \%data;
	}

There you have your array of hashes. Don't believe me? See the data
structure:

	use Data::Dumper;
	print Dumper \@record;

Now, getting the result you want... we'll first have to separate the
fields you want from the rest. 

	{
	    my @field = qw'Qty SKU Name NoTax Price';
	    my %included; @included{@field} = (1) x  @field;
	    my @extra = grep { !$included{$_} } @header;
	    local($\, $,) = ("ÿ", "þ");
	    # for testing only:
	      ($\, $,) = ("\n", "\t");
	    print @field;
	    foreach my $record (@record) {
	        my %hash = %$record;
	        for ($hash{Name} = join ' ', @hash{'Name', @extra}) {
	            # clean up:
	            tr/ //s;
	            s/ $//;
	        }   
	        print @hash{@field};
	    }
	}
p.s. It looks to me like you don't want "Total" in the "Name". It looks
silly.

-- 
	Bart.


------------------------------

Date: 2 Aug 2000 08:27:39 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Excessive memory use under OSF1 (was: numeric storage efficiency)
Message-Id: <965204260.2671@itz.pp.sci.fi>

In article <398797D4.EBA08E43@uiuc.edu>, Topher Cawlfield wrote:
>Okay, I have a self-contained Perl script that demonstrates this behavior. 
>I'm working at home on my Linux machine now, whereas this afternoon I was
>using Perl in OSF1 (on an Alpha).  After writing this test script, I see it
>behaves much better under Linux.  I probably have a newer version of Perl
>on Linux, which may be helping.  Here's the script.  I'm using the Unix ps

This seems to be architecture dependent: I can reproduce the problem
on "perl, v5.6.0 built for alpha-dec_osf", but not with the exact same
code run on either "perl, version 5.004_04 built for sun4-solaris" or
"perl, version 5.005_03 built for i386-linux".

I'd say you've hit a bug in the OSF1 port.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method."  -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.



------------------------------

Date: Wed, 02 Aug 2000 10:19:40 +0200
From: Sven <buggerm@de.ibm.com>
Subject: formating output
Message-Id: <3987D99B.29105543@de.ibm.com>

Hi everyone !
I want to put a formated text in a file:
The format looks like this:

format FRMT =
@<<<<<<<<<<@>>>>>>>>
$row[0],$row[2]
 .
format FRMT_TOP =
Page:@|||||
$%
======================
name            ID
 .

Th output file looks like this
Page 1
======================
---
Page 2

þ======================
^^

Where does this come from ?????

every page exept the first gets a stupid character at first place

Can anybody tell me why ?



------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 3879
**************************************


home help back first fref pref prev next nref lref last post