[15821] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3234 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 2 09:05:29 2000

Date: Fri, 2 Jun 2000 06:05:11 -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: <959951111-v9-i3234@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 2 Jun 2000     Volume: 9 Number: 3234

Today's topics:
    Re: AAAARRRRGGHHH! Please help <bill.kemp@wire2.com>
        Alternatives to Perl - DB/WWW interface <mark.hamlin@artdigital.co.uk>
    Re: Alternatives to Perl - DB/WWW interface <mark.hamlin@artdigital.co.uk>
    Re: Can not expire cookies !!! (jason)
    Re: Case-Insensitive String Comparison (Tad McClellan)
    Re: code cleanup <flavell@mail.cern.ch>
    Re: code cleanup (Bart Lateur)
        Compiling Perl-CGIs <mail@MAPLe-Soft.de>
    Re: Cookies stopped working w/Perl 5.6 (jason)
    Re: file dates being reported incorrectly..... (Bart Lateur)
        Globbing with ActivePerl <bdelmee@dilys.be>
        How to find out height and width of a PNG graphic <founder@pege.org>
        MacPerl, CGI, fixing long process timeout (Mark ONeil)
    Re: my Foo $self = shift; (Kai Henningsen)
    Re: Networking Perl for NT <Petri_member@newsguy.com>
    Re: Non-reuse of memory for lexically-scoped variables? <lr@hpl.hp.com>
    Re: Non-reuse of memory for lexically-scoped variables? (Ilya Zakharevich)
    Re: NT GROUP ? <gellyfish@gellyfish.com>
        OT (was Re: perl sites?) <phill@modulus.com.au>
    Re: Peculiar? Re-entrant Subroutines? (Bart Lateur)
    Re: Perl unusable as a programming language <dan@tuatha.sidhe.org>
    Re: problem with perl garbage collecting poppln@my-deja.com
    Re: Trouble with Arrays of Hashes <abe@ztreet.demon.nl>
        Using awk in perl? <apietro@my-deja.com>
    Re: Using awk in perl? <gellyfish@gellyfish.com>
    Re: wc for perl (jason)
        Will flock(...) wait? <thommy-p@bigfoot.com>
    Re: Will flock(...) wait? <lehotsky@tiac.net>
    Re: Win32::Eventlog (jason)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 2 Jun 2000 13:47:46 +0100
From: "W Kemp" <bill.kemp@wire2.com>
Subject: Re: AAAARRRRGGHHH! Please help
Message-Id: <959950176.24189.0.nnrp-12.c3ad6973@news.demon.co.uk>

<snip>
>#!/usr/bin/perl
>open(INPUT,'buh.data');
>while (<INPUT>) {
>        foreach $rec (@input) {
>        $a = substr($rec, 0, 1);
>        if ($a eq "/") {
>                $rec = "Unknown";
>        }
>        }
>        print "$rec\n";
>}
>
>If I run this, I get > 150,000 blank lines appearing on my screen - no
>record data is displayed, just empty space.  What am I doing wrong, and
>is there a better way to do this?


ignoring other faults mentioned elsewhere.

@input is not equal to anything (empty list)
So, the foreach does nothing, and $rec stays undefined.
(and if @input was a list/array of lines it would go through all of them,
changing $rec each time, but printing nothing, so you would only see what
happened to the last line in @input )

so, your script reads the file line by line, printing out an undefined value
and a newline each time, but completely ignoring what is in each line.

A chopped up version of your thing might be like this (and it isn't the way
i'd do it) :

while ($rec=<INPUT>) {
        $a = substr($rec, 0, 1);
        if ($a eq "/") {
                $rec = "Unknown\n";
        }
        print $rec;
}




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

Date: Fri, 02 Jun 2000 12:27:10 +0100
From: Mark Hamlin <mark.hamlin@artdigital.co.uk>
Subject: Alternatives to Perl - DB/WWW interface
Message-Id: <39379A0E.82020680@artdigital.co.uk>

Can anyone point me to articles giving a critical comparison of Perl and
PHP and maybe a mention on Cold Fusion as well, preferbaly with a slant
on DB & Web interfacing?

From a personal point of view, ie someone who has been using Perl for a
few years, I can little advantage in adopting PHP.  I am however
reviewing the products for a group of developers at very early stages in
a large R&D project, I am the only  one with Perl experience which I
must bear in mind.  Cold Fusion however looks like it might be
beneficial for ultra fast production to meet simple requirements in
addition to Perl.

Kind regards,
Mark Hamlin





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

Date: Fri, 02 Jun 2000 13:11:59 +0100
From: Mark Hamlin <mark.hamlin@artdigital.co.uk>
Subject: Re: Alternatives to Perl - DB/WWW interface
Message-Id: <3937A48F.407C85A6@artdigital.co.uk>

The first plus about PHP you'll probably mention is the fact that the code
is embedded in the HTML document - Is there a perl
system which will provide a similar setup.  I was reading about
FastTemplates earlier which is of great interest.

Found an article
http://news.tucows.com/ext2/99/06/submitted/061399-submitted3.shtml

Mark Hamlin

Mark Hamlin wrote:

> Can anyone point me to articles giving a critical comparison of Perl and
> PHP and maybe a mention on Cold Fusion as well, preferbaly with a slant
> on DB & Web interfacing?
>
> From a personal point of view, ie someone who has been using Perl for a
> few years, I can little advantage in adopting PHP.  I am however
> reviewing the products for a group of developers at very early stages in
> a large R&D project, I am the only  one with Perl experience which I
> must bear in mind.  Cold Fusion however looks like it might be
> beneficial for ultra fast production to meet simple requirements in
> addition to Perl.
>
> Kind regards,
> Mark Hamlin



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

Date: Fri, 02 Jun 2000 11:14:47 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: Can not expire cookies !!!
Message-Id: <MPG.13a234496e0f918a9896ff@news>

jbrzezi@my-deja.com writes ..
>I am using CGI::Cookie module.
>I can read cookies but I have problem with expiring them:
>
>I tried:
>
>@content_cookie=();
>%cookies = fetch CGI::Cookie;
>foreach(keys %cookies)   #get existing cookies
>  {
>    $current_cookie    = $cookies{$_};
>    $current_cookie->expires('-1d');
>    push(@content_cookie, $current_cookie);
>  }
>print header(-cookie=>\@content_cookie);
>
>according to documentation all the cookies with passed expiration date
>should not exist anymore.
>However when I read cookies again they are there !
>Any suggestions ?

reading some documentation on cookies .. the expire part of a cookie 
only affects how long the browser will hang on to it once it has been 
shut down

ie. while the browser is up - it will remember all cookies .. blank out 
the cookie value instead

-- 
 jason - elephant@squirrelgroup.com -


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

Date: Thu, 1 Jun 2000 20:09:24 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Case-Insensitive String Comparison
Message-Id: <slrn8je2a4.10l.tadmc@maxim.metronet.com>

On Thu, 1 Jun 2000 20:18:16 -0400, Courtney Tompos <cdt9@cornell.edu> wrote:
>Warning: Newbie =)

> Subject: Case-Insensitive String Comparison
                ^^^^^^^^^^^

What happened when you did a word-search for "insensitive"
in perlre (where Perl's regular expressions are described)?


   perldoc perlre


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 2 Jun 2000 13:07:07 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: code cleanup
Message-Id: <Pine.GHP.4.21.0006021256400.24347-100000@hpplus01.cern.ch>

On Fri, 2 Jun 2000, Bill wrote:

> I'm still new to PERL. Below, I've posted my very S L O P P Y and slow
> solution to my attempt to obtain the time 1 hour from the current time in a
> particular format.

Why are you doing this?  This just looks like a repeat of a question
posted a few hours ago asking how to create cookies.

Do it with CGI.pm.  Or plagiarise the code from there - it's in
CGI/Util.pm in (not surprisingly) sub expires.



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

Date: Fri, 02 Jun 2000 12:21:10 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: code cleanup
Message-Id: <393b987f.8685729@news.skynet.be>

Bill wrote:

>I'm still new to PERL. Below, I've posted my very S L O P P Y and slow
>solution to my attempt to obtain the time 1 hour from the current time in a
>particular format. I think I have indented it such that someone would easily
>be able to offer suggestions on cleaning it up ?

First of all, you don't need an external command to get the current date
and time. Perl has a built-in function for that: time(), which returns
the time in seconds since some starting time (called "the Epoch"; it
could be Jan 1st 1970 at 00:00:00 GMT). Add 60*60 to that, and you have
the time in 1 hour.

Second, Perl has two built-in functions, called localtim() and gmtime(),
to turn it into human recognizable form. They both have two standard
behaviours: in scalar context, they return a formatted string, and in
list context, they return the numeric fields necessary to do any hand
formatting yourself.

Try:

	print scalar localtime(time + 60*60);
 

But since throwing everything away and starting over won't teach you
much, I'll still go over your code, and try and improve on it.

>I am using Win2000 for my system "date" and "time"
>calls.

I hope that's compatible with Win98's date and time... Nope. It looks
like it's not. Oh well, the code will be untested then...

>Here is the working code (and yes I realize this won't accomodate Feb
>29 - hopefully I will have something better by then):

Something like the built-in localtime().

>$curtimefile="curtime.xxx";
>$curdatefile="curdate.xxx";
>
>system "time /t > $curtimefile";
>open MFILE, "<$curtimefile" || die "help!";
>read MFILE, $hh, 2;     # hour
>read MFILE, $sp, 1;     # next character (don't need it)
>read MFILE, $min, 2;    # minute
>close MFILE;

You're writing the output into an external file, and reading it in
again. If you use backticks instead of system(), you'll read the output
directly into a string.

	my $time = `time /t`;

Next, you read in a few bytes at a time. Don't. Read in the whole string
at once, so you get the whole string as I got in the above line.

Next, split the string into parts. unpack() with the "A" template, and a
regex, are two of the more obvious ways.

For $time, the regex /(..):(..)/ ought to work:

	my($min, $sec) = $time =~ /(..):(..)/;

or, using unpack():

	my($min, $sec) = unpack 'A2xA2', $time;

>system "date /t > $curdatefile";
>open MFILE, "<$curdatefile" || die "help!";
>read MFILE, $ww, 3;     # day of week
>read MFILE, $sp, 1;     # next character (don't need it)
>read MFILE, $mm, 2;     # month
>read MFILE, $sp, 1;     # next character (don't need it)
>read MFILE, $dd, 2;     # day of month
>read MFILE, $sp, 1;     # next character (don't need it)
>read MFILE, $yy, 4;     # year
>close MFILE;

	my $date = `date /t`;

unpack():

	my($ww,$mm,$dd,$yy) = unpack 'A3xA2xA2xA4', $date;

Or, and I guess the words are separated with whitespace:

	my($ww,$mm,$dd,$yy) = split /\s+/, $date;
	
>$hh++;        # increment the hour
>
>if ($hh eq "24") {

Numerical compare sounds better.

   if($hh == 24) {

>        $daychange = "1";
>        $hh = "00";
>}

>if ($daychange eq "1") {

You only need to test $daychange for True:

  if($daychange) {

>        if ($ww eq "Mon") {
>                $ww = "Tue";
>        } elsif ($ww eq "Tue") {
>                $ww = "Wed";
>        } elsif ($ww eq "Wed") {
>                $ww = "Thu";
>        } elsif ($ww eq "Thu") {
>                $ww = "Fri";
>        } elsif ($ww eq "Fri") {
>                $ww = "Sat";
>        } elsif ($ww eq "Sat") {
>                $ww = "Sun";
>        } else {
>                $ww = "Mon";
>        }

This sounds like a job for a hash. Let's see if I can make this cleanly:

	my @days = qw(Mon Tue Wed Thu Fri Sat Sun);
	my %nextday = map { $days[$_] => $days[$_+1 % @days] }
	      0 .. $#days;
	$ww = $nextday{$ww};

>        $dd++
>}

ok.

>if ($dd eq "32") {
>        $dd = "01";
>        $mm++;
>}
>
>if (($dd eq "31") && (($mm eq "04") || ($mm eq "06") || ($mm eq "09") ||
>($mm eq "11"))){
>                $dd = "01";
>                $mm++;
>}
>
>if (($dd eq "29") && ($mm eq "02")) {
>      $dd = "01";
>      $mm++;
>}

You have three different tests to see if the month has overflown, with
one (common) action. I think you should combine them into one orred
test.

First attempt:

   if($dd==32 or $dd==31 && ($mm==4 || $mm==6 || $mm==9 || $mm==11)
	or $mm==2 && (...)){

But, somehow, I think you overlooked something: what if $dd==30 and
$mm==2?

Furthermore, I think you should combine the month tests.

Here's a neat trick I once learned:
 
 a) consider Jan and Feb as belonging to the previous year, so subtract
2 (3) from the month number: March become month 0.
 b) take modulo 5 of that month number.
 c) on that result, the even numbered months (first month is zero, thus
even) are long months, the odd numbered month are short. So a bitwise
AND with 1 should give you a "short?" flag.

	$shortmonth = (($mm-3) %5 ) & 1;

The ultimate short month is February, to be treated separately (it's the
end of the previous year, so you can test if there aren't too many days
in that year).

The Perl way could well be, again, to use a lookup structure.

     @daysinmonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
     $overflow = $mm > $daysinmonth[$mm-1];

You can modify $daysinmonth[1] for February, if you must.

>if ($mm eq "13") {
>      $mm = "01";
>      $yy++;
>}

>
>@months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
>"Oct", "Nov", "Dec");
>$newmm = $months[--$mm];
>
>$newline = "\"$ww, $dd-$newmm-$yy $hh:$min:00 GMT\"";

This sounds like a job for printf()/sprintf(). It would be a bit safer,
always making sure that all numbers have enough digits.

    $newline = sprintf '"%s, %02d-%s-%04d %02d:%02d:%02d GMT"',
      $ww, $dd, $newmm, $yy, $hh, $mm, 0;

>print "one hour from now is $newline";

Don't you need a "\n" at the end of that?

-- 
	Bart.


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

Date: Fri, 2 Jun 2000 14:45:14 +0200
From: "Martin Plücker" <mail@MAPLe-Soft.de>
Subject: Compiling Perl-CGIs
Message-Id: <8h8aa3$rp6$12$1@news.t-online.com>

Hi!

Is there some method to compile Perl-CGIs so that they can be run with the
interpreter but the sources can't be seen or modified anymore?

Thanks
Martin




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

Date: Fri, 02 Jun 2000 11:21:48 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: Cookies stopped working w/Perl 5.6
Message-Id: <MPG.13a235f1a9b8ba27989700@news>

ericwinslow@yahoo.com writes ..
>print $r->header('cookie'=>$shit);
                  ^^
something's missing here

  perldoc CGI::Cookie

-- 
 jason - elephant@squirrelgroup.com -


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

Date: Fri, 02 Jun 2000 10:45:11 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: file dates being reported incorrectly.....
Message-Id: <393988f7.4709544@news.skynet.be>

scumjr wrote:

>> I find it suspicious that 31 Dec 69 is the day before the
>> Unix epoch. Might that be a clue?
>
>Not a clue to me??  What is the Unix Epoch?

Time in it's bare form, is stored as a number, in seconds. Seconds since
when? Since the Big Bang? Now that would be an extremely big number
(plus, not very deterministic). To keep things managable, and get a
relatively small number, there is a reference time: Time Zero, AKA the
Epoch. On Unix, it is Jan 1st 1970 at 00:00:00 hours. Other systems may
have copied that. All times are in seconds since The Epoch, which
currently fits in a 32 bit integer.

Yes, there may be some bumps in a not too distant future, around 2034 I
think. We hope that 64 bit integers, or at least 64 bit time
calculations, are common by then.

-- 
	Bart.


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

Date: Fri, 2 Jun 2000 12:33:35 +0200
From: "Bernard Delmée" <bdelmee@dilys.be>
Subject: Globbing with ActivePerl
Message-Id: <8h827r$lff$1@news0.skynet.be>

I noticed a while ago that wildcard expansion on the command
line seems to have changed with AP. Let's take a simple example:

C:\>    perl -e "print @ARGV;" *.*

On Win32, I know this works at least with perl4 and perl5.003
(build 315). It doesn't anymore as of build 520+, nor does 5.6.

Does someone know the trick?

TIA,
B.





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

Date: Fri, 2 Jun 2000 14:23:42 +0200
From: "Mösl Roland" <founder@pege.org>
Subject: How to find out height and width of a PNG graphic
Message-Id: <3937a74c$0$83464@SSP1NO17.highway.telekom.at>

I am far far away from being perfect in Perl,
but I am using Perl as my standard programing
language now.

I extracted from other scripts how to find out
height and width of a GIF or a JPG graphic,
but I did not find it until now for a PNG.

But I want to change all my sites to PNG
because of this idiotic patent threat with GIF

================================

sub get_graphic_size
{
  my ( $filename ) = @_;

  my ( $pic, $width, $height );

  my ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
$ctime, $blksize, $blocks )
  = stat ( $filename );

  if ( $size eq "" ) { return (0,0,0) }

  sub get_graphic_size_gif
  {
    my ( $filename ) = @_;
    open ( FILE, $filename );
    my $head;
    my @bool = ("no", "yes");
    my $gHeadFmt = "A6vvb8CC";
    my $pictDescFmt = "vvvvb8";
    read FILE, $head, 13;
    (my $GIF8xa, $width, $height, my $resFlags, my $bgColor, my $w2h) =
unpack $gHeadFmt, $head;
    return ( 1, $width, $height );
  }

  sub get_graphic_size_jpg
  {
    my ( $filename ) = @_;
    open ( FILE, $filename );
    binmode ( FILE );
    my($done)=0;
    my($c1,$c2,$ch,$s,$length, $dummy)=(0,0,0,0,0,0);
    my($a,$b,$c,$d);

    if ( read(FILE, $c1, 1) &&
         read(FILE, $c2, 1) &&
         ord($c1) == 0xFF &&
         ord($c2) == 0xD8 )
    {
      while (ord($ch) != 0xDA && !$done)
      {
      # Find next marker (JPEG markers begin with 0xFF)
      # This can hang the program!!
        while (ord($ch) != 0xFF) { return(0,0,0) unless read(FILE, $ch,
1); }
      # JPEG markers can be padded with unlimited 0xFF's
        while (ord($ch) == 0xFF) { return(0,0,0) unless read(FILE, $ch,
1); }
      # Now, $ch contains the value of the marker.
        if ((ord($ch) >= 0xC0) && (ord($ch) <= 0xC3))
        {
          return(0,0,0) unless read (FILE, $dummy, 3);
          return(0,0,0) unless read(FILE, $s, 4);
          ($a,$b,$c,$d)=unpack("C"x4,$s);
          return ( 1, $c<<8|$d, $a<<8|$b );
        }
        else
        {
          # We **MUST** skip variables, since FF's within variable names are
          # NOT valid JPEG markers
          return(0,0,0) unless read (FILE, $s, 2);
          ($c1, $c2) = unpack("C"x2,$s);
          $length = $c1<<8|$c2;
          last if (!defined($length) || $length < 2);
          read(FILE, $dummy, $length-2);
        }
      }
    }
    return (0,0,0);
  }

  if ( substr ( $filename, -4, 4 ) eq ".gif" )
  {
    ( $pic, $width, $height ) = get_graphic_size_gif ( $filename );
    close FILE;
    return ( $pic, $width, $height );
  }

  if ( substr ( $filename, -4, 4 ) eq ".jpg" )
  {
    ( $pic, $width, $height ) = get_graphic_size_jpg ( $filename );
    close FILE;
    return ( $pic, $width, $height );
  }

  return (0,0,0);
}


--
Mösl Roland http://www.pege.org
Clear targets for a confused civilization
http://www.BeingFound.com
web design and seminars
+43 699 17343674





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

Date: Fri, 02 Jun 2000 08:22:55 -0400
From: Mark.A.ONeil@Dartmotuh.EDU (Mark ONeil)
Subject: MacPerl, CGI, fixing long process timeout
Message-Id: <Mark.A.ONeil-0206000822550001@kiewit-off-bp-198.dartmouth.edu>

Since MacPerl does not support forking, how are others using MacPerl
handling CGIs which timeout due to their processing time?


Thanks,
-m


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

Date: 02 Jun 2000 14:22:00 +0200
From: kaih=7f50wpZmw-B@khms.westfalen.de (Kai Henningsen)
Subject: Re: my Foo $self = shift;
Message-Id: <7f50wpZmw-B@khms.westfalen.de>

kaih@khms.westfalen.de (Kai Henningsen)  wrote on 02.06.00 in <7f4wXLC1w-B@khms.westfalen.de>:

> Sure looks to me like someone invented a new feature and neglected to
> write the documentation for it.

Someone directed me to an older thread on this, and I see people getting  
directed to all manner of places that don't document this (duh!).

But the high point surely is Randal claiming man fields documents it.  
(Nope, it doesn't.) Followed by Jonathan claiming it's really discussed in  
attributes. (It's not even mentioned there, except in the context of  
(duh!) attributes - which are notably absent here.)

What *is* it with this collective blindness?

Kai
-- 
http://www.westfalen.de/private/khms/
"... by God I *KNOW* what this network is for, and you can't have it."
  - Russ Allbery (rra@stanford.edu)


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

Date: 2 Jun 2000 04:20:55 -0700
From: Petri Oksanen <Petri_member@newsguy.com>
Subject: Re: Networking Perl for NT
Message-Id: <8h85an$var@edrn.newsguy.com>

In article <8h7u6o$6m3$1@soap.pipex.net>, "Paul says...
>> I am having difficulty networking perl in an Windows environment.
>> I want perl to reside on the server and I want everyone to access
>> it including any packages that I install.
>> Its a centralization issue and I can't seem to get the clients to
>> work properly. Once I map the drive to the server I do a simple
>> "Perl -V" and it can't see the libaries.

> Which version of Perl?  Most NT versions I've seen set registry
> entries which indicate where the libraries are (as indicated by
> the INC array).

Isn't this what PERLLIB and the other environment variables are for?
Why hack the registry, follow perldoc perlrun instead.


Petri Oksanen



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

Date: Thu, 1 Jun 2000 18:01:41 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Non-reuse of memory for lexically-scoped variables?
Message-Id: <MPG.13a0a7538117a79898ab19@nntp.hpl.hp.com>

In article <3936D032.51FA5C51@earthlink.net> on Thu, 01 Jun 2000 
21:08:23 GMT, Denis Haskin <dwhaskin@earthlink.net> says...
+ Ilya Zakharevich wrote:
+ 
+ > No it is not.  Lexicals, compile-time and scratch variables are
+ > sticky: whatever goes there, remains there.
+ >
+ >   my $a = 'a';
+ >   my $b = 'b' x 1e6 . $a . $a;
+ >
+ > would take 3M (in recent Perls): one for 'b' x 1e6 (done at compile
+ > time), one for a scratch variable which contained b...ba, and one
+ > which sits in $b.  [Older Perls would take an extra 1M for b...baa
+ > in a scratch variable.]
+ >
+ > Only one of these Ms is recoverable, one in $b, and only by explicit
+ >
+ >   undef $b;
+ 
+ Arrrrrgh!  Is this really true?  This is nuts (but it may explain why 
I
+ think I have a memory leak)!
+ 
+ Shouldn't this be considered a bug?  So if I say:
+     {
+         my $b; # yes I know I can my and init at same time.
+         $b = 'x' x 1e6;
+     }
+ even though $b is out of scope once I'm out of the block, that memory
+ has been allocated and is not reused?  How can anyone write anything
+ of reasonable size & complexity in Perl if that's the case?
+ 
+ Is there a (good) reason that things work this way?

I don't think they work that way.   I would presume that Ilya's code is 
at file level, not within a block.

In the example you give, the storage allocated to $b should be marked 
reusable when the block is exited, because no reference to it exists.

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


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

Date: 2 Jun 2000 06:48:46 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Non-reuse of memory for lexically-scoped variables?
Message-Id: <8h7lce$md0$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Dan Sugalski 
<dan@tuatha.sidhe.org>],
who wrote in article <bnFZ4.99989$hT2.406636@news1.rdc1.ct.home.com>:
> Yep. If you entered the block once you may well enter it again, which
> means that perl keeps that memory more or less reserved just in case.
> basically the first scratchpad allocated for the block sticks around.
> Enter the block recursively and perl will allocate a new scratchpad for
> each reentry, but those are freed up on exit. (I think)

Nope.  BTW, there is a function in Devel::Peek to report on memory
confined in such places.

I checked it (many years ago), and at least in the simplest real-life
scripts the memory lost in such places is not *that* large.  However,
I would like to hear more about people examining their scripts.

> I'm not sure how to dodge this one--I think exiting an extra level of
> scope will do it, but I'm not 100% sure.

Short of deleting the subroutine: none.

Ilya


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

Date: Fri, 02 Jun 2000 12:14:44 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: NT GROUP ?
Message-Id: <UyNZ4.1781$6T1.373984@news.dircon.co.uk>

On Thu, 01 Jun 2000 17:19:45 -0400, Eli Mansour Wrote:
> Is there any newsgroup that I can post Win32 API calls ?

Probably somewhere in the microsoft.public.* hierarchy - what that has to
do with Perl I dont know.

/J\


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

Date: Fri, 02 Jun 2000 22:14:23 +1000
From: Peter Hill <phill@modulus.com.au>
Subject: OT (was Re: perl sites?)
Message-Id: <3937A51F.1108@modulus.com.au>

Jonathan Stowe wrote:
> 
> Please use complete words in your posts as this degree of abbreviation
> makes it difficult for people for whom english is not their native
> language.
> 
> /J\
Or,
Pls. use whole wrds in ur posts as this 0 of abbrvn. mks it hrd. for ppl
for whom engl. != ntv. lingo.

-- 
Peter Hill,
Modulus Pty. Ltd.,
http://www.modulus.com.au/


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

Date: Fri, 02 Jun 2000 10:45:07 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Peculiar? Re-entrant Subroutines?
Message-Id: <39388314.3202237@news.skynet.be>

Paris wrote:

>I was doing something peculiar with PERL the other day when I noticed
>what might be an unreported *feature*....
>I have a subroutine called 'search' which simply searches a text file
>for lines containing a given word.
>&search uses a *very* simple regular expression at it's core:
>
>if ($search_in =~ /$search_for/oi){$slice_ok = 1}else{last}

Note the //o modifier...

>Now the peculiar bit:
>I decided that if I wanted to cross reference the results of this file,
>against text taken from another file,

>It didn't work....
>The thing is, the re-entered &search subroutine works fine. PERL
>doesn't complain that I can't re-enter the routine before I have
>properly left it.

>It's just that the regular expression I mentioned above absolutely
>REFUSES to work.
>I have done some debugging, and there is no way that the regular
>expression shouldn't match.

Except... are you talking about the same regex pattern? If not...

>So here are my questions...
>Are subroutines in PERL re-entrant?

Yes.
>Why is the Regular Expression engine seemingly not re-entrant?

Necause of the //o modifier. Observe:

	sub match {
	    my($pattern, $string) = @_;
	    return $string =~ /$pattern/o?'match':'no match';
	}
	foreach ("A foo and a bar", "Only a foo", 
	  "Only a bar") {
	    print "$_: foo -> ",match('foo', $_), "\n";
	    print "$_: bar -> ",match('bar', $_), "\n";
	}
-->
	A foo and a bar: foo -> match
	A foo and a bar: bar -> match
	Only a foo: foo -> match
	Only a foo: bar -> match
	Only a bar: foo -> no match
	Only a bar: bar -> no match


The FIRST time the regex is executed, the pattern scalar is compiled
into the regex. Thanks to the //o modifier, it sticks. This means that
even if you pass it another pattern, it WON'T recompile. In my example,
because $pattern was 'foo' when first executed, the regex is /foo/
forever. So { 'Only a bar' =~ /$pattern/o } won't match, even with
$pattern set to 'bar'.

The solution? Call the search function only wit hone pattern in your
entire script. Hmmm... alright then, remove the //o modifier. But it
will slow down quite a bit. Hmmm...

There is no neat solution. What I usually do, is generate a function
through eval "sub { ... }" with the regex backed in, and do the search
through that sub.

	sub gensearch {
	    my $pattern = shift;
	    eval "sub { \$_[0] =~ /\$pattern/o }" 
	      or die $@;
	}
	my $searchfoo = gensearch('foo');

#call as:
	print $searchfoo->($_)?'match':'no match';


p.s. Unfortunately, the //o modifer and closures (without the "eval")
don't work well together. There's globally only one regex, so the
problem still pertains.

-- 
	Bart.


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

Date: Fri, 02 Jun 2000 02:51:52 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Perl unusable as a programming language
Message-Id: <cjFZ4.99988$hT2.406636@news1.rdc1.ct.home.com>

In comp.lang.perl.misc Malcolm Dew-Jones <yf110@victoria.tc.ca> wrote:
> Dan Sugalski (dan@tuatha.sidhe.org) wrote:
> : In comp.lang.perl.misc Malcolm Dew-Jones <yf110@victoria.tc.ca> wrote:

> : > That might be either a bug or a misunderstanding on my part. 

> : Misunderstanding. Which is understandable, since it's both kinda odd and
> : undocumented.

> Nice example, thanks.

> Threads such as this as good for learning things.  I have been forced to
> clarify my understanding of local. 

Don't use this as a way to understand local. What we're talking about here
actually has nothing to do with local, and everything to do with where
match variables live in perl's space.

Package variables, the things you can local()ize, live in the symbol table
and are persistent--their values stick until you change them. If you
localize them, the change sticks until the local goes out of scope. When a
block exits, perl cleans up things that should be cleaned up when a block
goes away.

Lexical variables live in scratchpads, which are attached to blocks. Enter
a block and a new scratchpad is allocated. Recursively enter a block and a
new scratchpad is allocated again. Exit the block and the scratchpad for
that block is cleaned out. (It's a touch more complex than this due to
some optimizations, but this is pretty much it)

Match variables, on the third hand, are neither package variables living
in the ssymbol table nor lexicals living in a scratchpad. They are,
instead, attached directly to the tree of opcodes that perl builds when it
compiles your program. It sort of looks like they're localized in blocks,
because when you start a new block perl marks the section of the optree in
the block as using a different area of memory to hold the matches. They
really aren't, though, which is why the recursive example acts the way it
does--even though you're recursing and entering new blocks (as far as
lexicals are concerned) and exiting blocks (as far as local() would be
concerned), you're executing the exact same chunk of the optree over and
over, hence reusing (and stomping on) the match variable space attached to
that part of the optree.

Yes, it is odd, and making it Not Do That will likely be tricky. ("Here
there be dragons," and "Abandon all hope, ye who enter here" and stuff
like that)

				Dan


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

Date: Fri, 02 Jun 2000 11:18:46 GMT
From: poppln@my-deja.com
Subject: Re: problem with perl garbage collecting
Message-Id: <8h856d$evn$1@nnrp1.deja.com>

In article <8h4hh6$i2m$1@charm.magnus.acs.ohio-state.edu>,
  ilya@math.ohio-state.edu (Ilya Zakharevich) wrote:
> Even if the debugger is run non-interactively in non-stop mode?

How do you run the debugger non-interactively?
I run the scripts with perl -wd ... and when I get the prompt I enter
c<ENTER> and it runs to the end.

>
> If yes, try to fiddle with bits of $^P until you can reproduce the
> change without -d.  Keep in mind that with a Perl so old directly
> fiddling with a couple of bits of $^P would lead to a segfault.  [But
> you will find them soon enough. ;-]

perl-5.00502 is old?
What is the must updated version? ( before 5.6 - I need a perl that
WORKS! )
   Nadav


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


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

Date: Fri, 02 Jun 2000 13:33:11 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Trouble with Arrays of Hashes
Message-Id: <qi5fjsk727ocfqtn8tvhiv8f18hnn3p4sd@4ax.com>

On Thu, 01 Jun 2000 14:01:22 -0700, Tony Lanier
<tlanierNOtlSPAM@atmel.com.invalid> wrote:

> Hi,
Hi,
> 
> I have been having trouble using an Array of Hashes (AoH). The
> file that I am parsing looks like this:
> 
> Library: common SClib
> Library: common Common
> Library: at5600 StdLib
> 
> I'm generating the AoH like this:
> 
> if (/Library:/)
> {
> 	$library{$line[1]} = $line[2];
> 	push @AoH, {%library};				
> }
> 
Keeping in mind what Sam Holden said about the hash (%library) not being
cleared of it's previous data, I think this is rather poor design for
the case at hand. You are creating a list of hashes over which you have
little control (and it bites back at you). That could easily be
prevented by assigning the values to known keys in the hash:

	my %library = (	type => $line[1], lib  => $line[2] );

or push an anon. hash directly onto @AoH:

	push @AoH, { type => $line[1], lib => $line[2] };

This allows you to 'assemble' $sim_libraries with one simple join/map:

	my $sim_libraries = join ' ', 
		map { "-y $cbic_kit/$_->{type}/$_->{lib}" } @AoH;

	

-- 
Good luck,
Abe


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

Date: Fri, 2 Jun 2000 11:05:35 +0100
From: "A Pietro" <apietro@my-deja.com>
Subject: Using awk in perl?
Message-Id: <8h80tt$ld9$1@sshuraac-i-1.production.compuserve.com>

Can I include an awk or sed command, or even a shell script, in my Perl
code?

* If so, do I use "backqoute" syntax to do this?
* Will my script run faster if I do things such as pulling fields out of a
config file using awk, rather than reading them into a perl assocuiative
array ?
* Any simple examples would be welcome.


Thanks
AP




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

Date: Fri, 02 Jun 2000 12:13:30 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Using awk in perl?
Message-Id: <KxNZ4.1780$6T1.373984@news.dircon.co.uk>

On Fri, 2 Jun 2000 11:05:35 +0100, A Pietro Wrote:
> Can I include an awk or sed command, or even a shell script, in my Perl
> code?
> 
> * If so, do I use "backqoute" syntax to do this?
> * Will my script run faster if I do things such as pulling fields out of a
> config file using awk, rather than reading them into a perl assocuiative
> array ?
> * Any simple examples would be welcome.
> 

You can use a2p to convert your awk stuff into slightly less than idiomatic
Perl.

/J\


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

Date: Fri, 02 Jun 2000 11:10:07 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: wc for perl
Message-Id: <MPG.13a233367a5150a19896fe@news>

crotchless gespatcho writes ..
>You know, I have been to the PPT site for diff and wc and I
>cannot get the code because it is one line.  I have tried in both
>IE4 and Netscape.  Is there a way to download the code in a
>readable format?

in IE (assuming Windows OS with default Notepad TXT file viewer)

  View > Source > File > Save As

I'm sure you can take it from there

-- 
 jason - elephant@squirrelgroup.com -


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

Date: Fri, 2 Jun 2000 13:38:46 +0200
From: "Thomas Plehn" <thommy-p@bigfoot.com>
Subject: Will flock(...) wait?
Message-Id: <8h86de$a1h$15$1@news.t-online.com>

Hi,
can anyone help me with these flock questions?

I have to use LOCK_EX for a special listfile, because it would be fatal if
another script tried to read from it while it is modified.

Is there any better solution to wait for read-access than the one below?

while(not(-r "myfile.dat")){sleep(1);}
open(FILE, "<myfile.dat");

I wondered what will happen if LOCK_EX is called while another script is
reading from the file without any lock.

It is important that my list_read()-routines don't use any flock()-call,
however my list_update()-routine _must_ use LOCK_EX.

Thanks in advance
Thomas




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

Date: Fri, 02 Jun 2000 08:36:41 -0400
From: Alan Lehotsky <lehotsky@tiac.net>
Subject: Re: Will flock(...) wait?
Message-Id: <lehotsky-227F3D.08364102062000@news.tiac.net>

In article <8h86de$a1h$15$1@news.t-online.com>, "Thomas Plehn" 
<thommy-p@bigfoot.com> wrote:

>>>Hi,
>>>can anyone help me with these flock questions?
>>>
 ...


>>>
>>>I wondered what will happen if LOCK_EX is called while another script is
>>>reading from the file without any lock.
>>>


   Unix file locking is ALWAYS advisory.  It only works if all
accessors announce their intentions.  If you do a create() with
the open-exclusive option, THEN you can guarantee that you
aren't writing something that someone else is reading (because
you'll be told if the file already exists)

-- Al

-- 
                Quality Software Management
             http://www.tiac.net/users/lehotsky

Process Improvement | Management Consulting | Compiler Implementation


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

Date: Fri, 02 Jun 2000 11:27:28 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: Win32::Eventlog
Message-Id: <MPG.13a2374362c37d15989701@news>

Eli Mansour writes ..
>Can somebody give me an example of writing an error to
>to NT eventlog.
>
>I can' seem to get the syntax straight.

the following code will work with my EventLog.pm .. but from memory I 
had to change a couple of things in the Report method because they were 
set up more for reading from the event log rather than writing to it 
(from memory the Source element of the hash was incorrectly implemented)

let me know how the following code goes because I'd be surprised if 
EventLog wasn't fixed up - the code below certainly works with (what I'm 
fairly sure is) a fresh installation of v5.6


#!/usr/bin/perl -w
use strict;

use Win32::EventLog;

my $ref = new Win32::EventLog( 'my app', 'fire');

Win32::EventLog::Report( { Computer => $ENV{COMPUTERNAME}
               , Source => 'my application'
               , EventType => EVENTLOG_WARNING_TYPE
               , EventCategory => 0
               , EventID => 0
               , Data => ''
               , Strings => 'Something new here'
               }
             );

__END__


-- 
 jason - elephant@squirrelgroup.com -


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

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 3234
**************************************


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