[19261] in Perl-Users-Digest
Perl-Users Digest, Issue: 1456 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 7 00:05:39 2001
Date: Mon, 6 Aug 2001 21:05:07 -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: <997157106-v10-i1456@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 6 Aug 2001 Volume: 10 Number: 1456
Today's topics:
Re: ActiveState Perl <-> Cygwin perl and newlines... <gimi@psico.ch>
Re: config for @INC ... more info <gimi@psico.ch>
databasing <jtjohnston@courrier.usherb.ca>
javascript and LWP::UserAgent <cak@putzl.com>
Re: launching a perl program not in a window (Randal L. Schwartz)
Re: launching a perl program not in a window <ow22@nospam-cornell.edu>
One more uploading question... <Gala@nonono.com>
Re: One more uploading question... <dbe@wgn.net>
Re: Pairwise foreach-like idiom (Logan Shaw)
Re: Pattern Matching: Which subpattern (rather than sub <krahnj@acm.org>
Re: Pattern Matching: Which subpattern (rather than sub <krahnj@acm.org>
Re: Pattern Matching: Which subpattern (rather than sub <gimi@psico.ch>
Pattern Matching: Which subpattern (rather than substri <barsticus@earthling.net>
Perl5 memory leak or garbage collection problems? weigand@DONTMESSWITHtexas.net
Re: Perl5 memory leak or garbage collection problems? <brentdax1@earthlink.net>
Re: prompting and redirection with ssh <billy_dont_try@verizon.net>
Re: q: launching a perl script from a perl script <gimi@psico.ch>
Re: q: launching a perl script from a perl script <gimi@psico.ch>
Re: Sending e-mail from a script in MS windows <dan@nospam_dtbakerprojects.com>
Re: Trouble Finding Parse::RecDescent for Perl 5.004 (Randal L. Schwartz)
Re: validate IP address <EvR@compuserve.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Aug 2001 04:01:27 +0200
From: gimi <gimi@psico.ch>
Subject: Re: ActiveState Perl <-> Cygwin perl and newlines...
Message-Id: <3B6F4BF7.4EBFEC7E@psico.ch>
hi
Simon Andrews wrote:
> I seem to remember that there is also a global variable you can set to
> change the default line ending (hopefully someone will leap in and
> remind me which one!). Changing that at the top of your script should
$OUTPUT_RECORD_SEPARATOR or something.. see pervar.pod
but 'tis not what you want, 'cause this will be
at the end of every print; ..
> generate the correct line endings from that point on (it changes the
> characters output by \n). Perldoc perlvar will probably have the
> details you need.
yes. -- er, no. :)
i use to just ignore that and use an editor/
textviewer that *can* handle unix\n text on
windowns. - keep it simple, don't change the
world.
jm2c
gimi
--
http://www.psico.ch/
------------------------------
Date: Tue, 07 Aug 2001 04:15:40 +0200
From: gimi <gimi@psico.ch>
Subject: Re: config for @INC ... more info
Message-Id: <3B6F4F4C.E03607D6@psico.ch>
Dan Baker wrote:
>
> a little more testing confirms that the machine that behaves as expected
> considers the working directory ./ to be the dir that whatever.pl is
> executed in via the double-click. The machine that DOESN'T work "right"
> always treats ./ like it is c:\usr\bin , which is where the perl.exe is
> installed.
>
> This *may* be the root of the issues for me, so my question is:
>
> - in windows98, how can I change the double-click execution of a perl
> script to use the dir that the script is in as the default working
> directory for the MS-DOS process that opens and runs, rather than using
> the dir that the perl executable is in?
>
> thanx,
>
> D
i'd go for autoexec.bat and add something like
path=%PATH%;C:\myyperl\bin\;.
or whatever you put your perl into :)
you will have that and the current dir as path
in every dos box you open.
or place some shortcut on your desktop, change
the 'opens in...' (and maybe the other text field..
still dunno what it's called in english windows vers.
- above that, anyway) to the correct paths.
phphh.... hth after seven or so beers
(been playing cs all night ;)
------------------------------
Date: Tue, 07 Aug 2001 01:08:23 GMT
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: databasing
Message-Id: <3B6DEE73.3C4B8DC8@courrier.usherb.ca>
Could anyone help with a script you helped me refine last week?
I have tried, but can't get my new changes to work.
I have a database.txt
--------------snip------------
1¶field1¶field2¶field3¶field4¶field5¶field6¶field7¶field8¶field9¶field10¶
2¶field1¶field2¶field3¶field4¶field5¶field6¶john¶field8¶field9¶field10¶
3¶field1¶field2¶field3¶field4¶field5¶field6¶&&1;john;susan;dave;&&5;April;March;¶field8¶field9¶field10¶
4¶field1¶field2¶field3¶field4¶field5¶field6¶dave¶field8¶field9¶field10¶
5¶field1¶field2¶field3¶field4¶field5¶field6¶&&1;john;susan;dave;&&5;April;March;¶field8¶field9¶field10¶
6¶field1¶field2¶field3¶field4¶field5¶field6¶john¶field8¶field9¶field10¶
7¶field1¶field2¶field3¶field4¶field5¶field6¶dave¶field8¶field9¶field10¶
--------------snip------------
I am trying to parse out the contents of field7 and count the number of
instances each occurs.
I have this so far:
-------------snip-----------------
open (THEFILE, $file) or die ("Can't open $file: $!");
while (<THEFILE>) {
$count{(split(/\¶/))[7]}++;
}
foreach (sort keys %count) {
print "$_¶$count{$_}¶\n";
}
-------------snip-----------------
This results:
dave¶2¶
field7¶1¶
john¶2¶
mary¶1¶
Now I have a new dilemna. Record 3 & 5 now include some weird stuff,
which I want to include in the count. The result should take this into
consideration:
&&1;john;susan;dave;&&5;April;March;
I will need to delete the &&1 to &&9 and divide the contents of field7
by ";".
$_ =~ s/&&[1-9];//g; #or something like that
Could anyone help me refine my code? to result this:
dave¶4¶
field7¶1¶
john¶4¶
mary¶1¶
susan¶2¶
April¶2¶
March¶2¶
Thanks so much for your help,
John
------------------------------
Date: Mon, 06 Aug 2001 19:23:55 -0700
From: Chris Kantarjiev <cak@putzl.com>
Subject: javascript and LWP::UserAgent
Message-Id: <3B6F513B.B4879008@putzl.com>
I'm trying to automate submission to a web form that has some JavaScript
on it - in particular, http://www.expedia.com/pub/agent.dll?qscr=flin
Here's a fragment of my code:
my $ua = LWP::UserAgent->new();
$ua->agent("Schmozilla/v9.14 Platinum");
my $URL = "http://www.expedia.com/pub/agent.dll?qscr=flin";
my $res = $ua->request(GET $URL);
print $res->content, "\n";
This is with the intent of using HTMP::TreeBuilder and
HTMP::Request::Form to parse and fill in the form, but at this point,
I'm getting an error from the site saying that I don't have scripting
enabled. I can't see anything in the LWP documentation about how to turn
this on, though.
I had also tried another approach, using the POST method on the form
that gets generated by this URL, but all I ended up getting was a bunch
of redirects. I'm guessing that I haven't understood the form contents
correctly - there are a bunch of INPUT fields that I have filled in
(presumably correctly) but the link that a human would click on is
<A ID=A4501_13209 HREF="javascript:SubmitForSpecificFlightSearch()"><IMG
SRC="/eta/btn_sec.gif" BORDER=0 ALIGN=LEFT> Display flight
status.</A></TD></TR>
and I'm not really sure how to invoke this with a "simple" POST. The
HREF points to this code:
function SFSP(f,t,x,m,r)
{
f.submit();
}
var
gWSDS="6AC872EF!9015101000100002!D0100001!A03!60$E0$80$E9Z13!60$E0$80$E9Z13!60$E0$80$E9Z13!60$E0$80$E9Z13!60$E0$80$E9Z1!Q0";
var f=document.FltWiz;
function SubmitForSpecificFlightSearch()
{
f.wsds.value=gWSDS;
f.qscr.value="flin";
f.flag.value = "x";
SFSP(f,'Expedia.com is getting your arrival/departure information.
Please wait.');
}
which could, for all I know, be dynamically generated (that sure looks a
lot like a GUID).
Help?
Thanks,
chris
------------------------------
Date: 06 Aug 2001 20:19:28 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: launching a perl program not in a window
Message-Id: <m1ofpssgjj.fsf@halfdome.holdit.com>
>>>>> "Oliver" == Oliver <ow22@cornell.edu> writes:
Oliver> yea i posted it there first, but no one ever answers.
What the Javascript answers or does not answer is of no concern to the
Perl group, and does not give one permission to post off topic.
Also, remember that great wisdom:
Get real! This is a discussion group, not a helpdesk. You post
something -- we discuss its implications. If the discussion happens
to answer a question you've asked, that's incidental.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Mon, 6 Aug 2001 20:56:25 -0700
From: "Oliver" <ow22@nospam-cornell.edu>
Subject: Re: launching a perl program not in a window
Message-Id: <9knoto$g4v$1@news01.cit.cornell.edu>
"Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message
news:m1ofpssgjj.fsf@halfdome.holdit.com...
> >>>>> "Oliver" == Oliver <ow22@cornell.edu> writes:
>
> Oliver> yea i posted it there first, but no one ever answers.
>
> What the Javascript answers or does not answer is of no concern to the
> Perl group, and does not give one permission to post off topic.
>
> Also, remember that great wisdom:
>
> Get real! This is a discussion group, not a helpdesk. You post
> something -- we discuss its implications. If the discussion happens
> to answer a question you've asked, that's incidental.
>
hm i didnt think the question off-topic, because it does deal with perl. but
anyway when did i complain that my question was not answered, steffen muller
answered it in the first post. what followed were totally unrelated.
------------------------------
Date: Tue, 07 Aug 2001 01:41:51 GMT
From: "Gala" <Gala@nonono.com>
Subject: One more uploading question...
Message-Id: <zHHb7.36916$Kd7.22777217@news1.rdc1.sfba.home.com>
First off, I wanna thank everyone who helped me out in my last post! I haave the uploading part working. I just have a
question. How can I determine when I should use binmode() ?
For example: I'm on a win98 machine, my serrver is runing linux. I wanna upload a perl source file (.pl or .cgi) (which would
need to be trasfered in "ascii mode", like in ftp).
I know I can do:
my $file = $q->param("file") || print "No file specified.";
my $filetype = $q->uploadInfo($file)->{'Content-Type'};
to get the content-type, and I could jsut compare that to see if it should be tranfered as "binary" or "ascii" mode. But
there are so many differnent types, and I'm making this script to eventually be part of a file manager I'm making, so I want
to be able to upload any binary file (executable, image, etc) without corruption and also as ascii for text files that should
be converted, and work regardless of platform (of user and the server). Is there a known/preferable way to do this? I hope
I'm not asking a lot here.
Thanks a lot for any help!
------------------------------
Date: Mon, 06 Aug 2001 19:47:07 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: One more uploading question...
Message-Id: <3B6F56AB.11A4ACB1@wgn.net>
Gala wrote:
>
> First off, I wanna thank everyone who helped me out in my last post! I haave the uploading part working. I just have a
> question. How can I determine when I should use binmode() ?
> For example: I'm on a win98 machine, my serrver is runing linux. I wanna upload a perl source file (.pl or .cgi) (which would
> need to be trasfered in "ascii mode", like in ftp).
>
> I know I can do:
> my $file = $q->param("file") || print "No file specified.";
> my $filetype = $q->uploadInfo($file)->{'Content-Type'};
>
> to get the content-type, and I could jsut compare that to see if it should be tranfered as "binary" or "ascii" mode. But
> there are so many differnent types, and I'm making this script to eventually be part of a file manager I'm making, so I want
> to be able to upload any binary file (executable, image, etc) without corruption and also as ascii for text files that should
> be converted, and work regardless of platform (of user and the server). Is there a known/preferable way to do this? I hope
> I'm not asking a lot here.
binmode is ignored on UNIX since all characters whether binary or not
are treated the same in the data transfer. So whatever arrives at
the UNIX box will end up in the file.
You could if you wish, remove the \r's from text files in your script,
but it shouldn't be necessary if they aren't going to be executable
(eg: a Perl script - which you would want to remove the \r's from
at least on the shebang line).
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:dbe@todbe.com
/ ) /--< o // // http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
------------------------------
Date: 6 Aug 2001 20:45:28 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Pairwise foreach-like idiom
Message-Id: <9knh7o$f0o$1@charity.cs.utexas.edu>
In article <20010806172242.453$30@newsreader.com>, <ctcgag@hotmail.com> wrote:
>I've run into this problem and problems similar several times.
>I want to visit the neighbors of a given datapoint, $x[$j][$i],
>but have it flexible (so I can add diagonal neighbers, etc.)
>
>The solution I came up with is this:
>
>@group = ( -1,0, +1,0, 0,-1, 0,+1 );
>while ( ($io, $jo, @group ) = @group ) {
> $ii=$i+$io;
> $jj=$j+$jo;
> -- Do something with $x[$jj][$ii] --
>};
I would probably do this:
@offsets =
(
[-1, 0],
[ 1, 0],
[ 0, -1],
[ 0, 1]
);
$i = 42;
$j = 99;
foreach my $offset (@offsets)
{
my $ii = $i + $offset->[1];
my $jj = $j + $offset->[0];
# do something with $array[$jj][$ii]
}
Another option is to apply the offsets to the coordinates all at once
up front, and then loop over the resulting pairs:
@offsets =
(
[-1, 0],
[ 1, 0],
[ 0, -1],
[ 0, 1]
);
$i = 42;
$j = 99;
foreach my $pair (map ([ $i + $_->[1], $j + $_->[0] ], @offsets))
{
my ($ii, $jj) = @$pair;
# do something with $array[$jj][$ii]
}
Another way is similar to what you gave, although maybe a little more
efficient because it doesn't assign the array repeatedly (and shift()
has O(1) execution time):
@offsets =
(
-1 => 0,
1 => 0,
0 => -1,
0 => 1
);
$i = 42;
$j = 99;
while (@offsets > 0)
{
my $ii = shift @offsets + $i;
my $jj = shift @offsets + $j;
# do something with $array[$jj][$ii]
}
I'm sure there are other ways, too.
- Logan
--
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)
------------------------------
Date: Tue, 07 Aug 2001 02:37:42 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Pattern Matching: Which subpattern (rather than substring) was matched?
Message-Id: <3B6F54C3.42AB6E49@acm.org>
Simon Best wrote:
>
> Here's what I want to do. I want to find out which subpattern in a
> regular expression was the one that matched the matched string, if there
> was a match. But I don't mean backreferences as such, like $1, $2, etc,
> 'cause they're the matched substrings, not the subpatterns that those
> substrings matched.
>
> For example, I could have:
>
> $STRING =~ m/($SUBPATTERN1)|($SUBPATTERN2)|($SUBPATTERN3)/;
>
> and, if $STRING eq "Blah blah blah $SOMETHING_MATCHING_SUBPATTERN2 blah
> blah.", I'd want to know that it was $SUBPATTERN2 that matched. I'd
> like something like backreferences, but where it's $SUBPATTERN2 that's
> given, not $SOMETHING_MATCHING_SUBPATTERN2.
>
> Does that make sense?
>
> Anyway, the reason I wish to do this is because I wish to find the
> earliest match (the one furthest to the left in the string) out of a
> number of alternatives, and know which alternative it was that matched.
> (I intend to use the patterns as hash keys, so as to access stuff, in a
> hash, that's relevant to each kind of string.)
>
> I could write a function to do it, but it just seems nicer, somehow, to
> have Perl's pattern matching engine doing the business, as it already
> does it the way I need it to. It just doesn't seem to say (as far as I
> can tell) which subpattern was actually matched.
>
> Anyway, if there is a quick'n'easy way of finding which subpattern
> matched, I'd like to know!
>
> Thanks to anyone who might have an answer :-)
defined $-[$_] and print "Matched pattern number $_\n" for 1 .. $#-;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 07 Aug 2001 02:48:15 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Pattern Matching: Which subpattern (rather than substring) was matched?
Message-Id: <3B6F573D.550A3720@acm.org>
"John W. Krahn" wrote:
>
> Simon Best wrote:
> >
> > Here's what I want to do. I want to find out which subpattern in a
> > regular expression was the one that matched the matched string, if there
> > was a match. But I don't mean backreferences as such, like $1, $2, etc,
> > 'cause they're the matched substrings, not the subpatterns that those
> > substrings matched.
> >
> > For example, I could have:
> >
> > $STRING =~ m/($SUBPATTERN1)|($SUBPATTERN2)|($SUBPATTERN3)/;
> >
> > and, if $STRING eq "Blah blah blah $SOMETHING_MATCHING_SUBPATTERN2 blah
> > blah.", I'd want to know that it was $SUBPATTERN2 that matched. I'd
> > like something like backreferences, but where it's $SUBPATTERN2 that's
> > given, not $SOMETHING_MATCHING_SUBPATTERN2.
> >
> > Does that make sense?
> >
> > Anyway, the reason I wish to do this is because I wish to find the
> > earliest match (the one furthest to the left in the string) out of a
> > number of alternatives, and know which alternative it was that matched.
> > (I intend to use the patterns as hash keys, so as to access stuff, in a
> > hash, that's relevant to each kind of string.)
> >
> > I could write a function to do it, but it just seems nicer, somehow, to
> > have Perl's pattern matching engine doing the business, as it already
> > does it the way I need it to. It just doesn't seem to say (as far as I
> > can tell) which subpattern was actually matched.
> >
> > Anyway, if there is a quick'n'easy way of finding which subpattern
> > matched, I'd like to know!
> >
> > Thanks to anyone who might have an answer :-)
>
> defined $-[$_] and print "Matched pattern number $_\n" for 1 .. $#-;
Sorry, should be simpler:
print "Matched pattern number $#-\n"
# OR
print "Matched pattern number $#+\n"
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 07 Aug 2001 04:59:19 +0200
From: gimi <gimi@psico.ch>
Subject: Re: Pattern Matching: Which subpattern (rather than substring) was matched?
Message-Id: <3B6F5987.C1537AFC@psico.ch>
hi
Simon Best wrote:
> I'm new here. But anyway...
i'm not, but who cares..
> Here's what I want to do. I want to find out which subpattern in a
> regular expression was the one that matched the matched string, if there
> was a match. But I don't mean backreferences as such, like $1, $2, etc,
> 'cause they're the matched substrings, not the subpatterns that those
> substrings matched.
>
> For example, I could have:
>
> $STRING =~ m/($SUBPATTERN1)|($SUBPATTERN2)|($SUBPATTERN3)/;
>
> and, if $STRING eq "Blah blah blah $SOMETHING_MATCHING_SUBPATTERN2 blah
> blah.", I'd want to know that it was $SUBPATTERN2 that matched. I'd
> like something like backreferences, but where it's $SUBPATTERN2 that's
> given, not $SOMETHING_MATCHING_SUBPATTERN2.
not cool, but it would work this way:
$string =~ /$subpattern1/ and print "matched $subpattern1\n"
or $string =~ /$subpattern2/ and print "matched $subpattern2\n"
# and so on
;
so you would know which.
> Anyway, the reason I wish to do this is because I wish to find the
> earliest match (the one furthest to the left in the string) out of a
> number of alternatives, and know which alternative it was that matched.
as for the 'earliest'.. ask pos() every time and compare the
numbers you get. see
% perldoc -f pos
> (I intend to use the patterns as hash keys, so as to access stuff, in a
> hash, that's relevant to each kind of string.)
>
> I could write a function to do it, but it just seems nicer, somehow, to
> have Perl's pattern matching engine doing the business, as it already
> does it the way I need it to. It just doesn't seem to say (as far as I
> can tell) which subpattern was actually matched.
i don't think so, yes. - but it can be worked around,
so to speak.
> Anyway, if there is a quick'n'easy way of finding which subpattern
> matched, I'd like to know!
i'm easy. :D
gimi
--
http://www.psico.ch/
------------------------------
Date: Tue, 07 Aug 2001 02:40:36 +0100
From: Simon Best <barsticus@earthling.net>
Subject: Pattern Matching: Which subpattern (rather than substring) was matched?
Message-Id: <3B6F4713.30EFC96B@earthling.net>
Hello!
I'm new here. But anyway...
Here's what I want to do. I want to find out which subpattern in a
regular expression was the one that matched the matched string, if there
was a match. But I don't mean backreferences as such, like $1, $2, etc,
'cause they're the matched substrings, not the subpatterns that those
substrings matched.
For example, I could have:
$STRING =~ m/($SUBPATTERN1)|($SUBPATTERN2)|($SUBPATTERN3)/;
and, if $STRING eq "Blah blah blah $SOMETHING_MATCHING_SUBPATTERN2 blah
blah.", I'd want to know that it was $SUBPATTERN2 that matched. I'd
like something like backreferences, but where it's $SUBPATTERN2 that's
given, not $SOMETHING_MATCHING_SUBPATTERN2.
Does that make sense?
Anyway, the reason I wish to do this is because I wish to find the
earliest match (the one furthest to the left in the string) out of a
number of alternatives, and know which alternative it was that matched.
(I intend to use the patterns as hash keys, so as to access stuff, in a
hash, that's relevant to each kind of string.)
I could write a function to do it, but it just seems nicer, somehow, to
have Perl's pattern matching engine doing the business, as it already
does it the way I need it to. It just doesn't seem to say (as far as I
can tell) which subpattern was actually matched.
Anyway, if there is a quick'n'easy way of finding which subpattern
matched, I'd like to know!
Thanks to anyone who might have an answer :-)
Simon Best
--
_______________________________________________________________________________
email: barsticus@earthling.net
website: http://www.cydonia.f2s.com
------------------------------
Date: Tue, 07 Aug 2001 01:59:05 GMT
From: weigand@DONTMESSWITHtexas.net
Subject: Perl5 memory leak or garbage collection problems?
Message-Id: <JXHb7.115528$Cu6.8899914@bin3.nnrp.aus1.giganews.com>
I've discovered a MAJOR bug in some Perl 5 builds, including the
latest one it looks like. The problem has to do with the way Perl
does garbage collection. Here's an example program to be run on
Linux, Solaris, or other unices:
#!/usr/local/bin/perl5
%T = ();
system("vmstat 1 2");
$T{"one"}{"two"} = "1" x 200000000;
system("vmstat 1 2");
%T = ();
system("vmstat 1 2");
$T{"one"}{"two"} = "1" x 200000000;
system("vmstat 1 2");
%T = ();
system("vmstat 1 2");
$T{"one"}{"two"} = "1" x 200000000;
system("vmstat 1 2");
%T = ();
system("vmstat 1 2");
$T{"one"}{"two"} = "1" x 200000000;
system("vmstat 1 2");
%T = ();
system("vmstat 1 2");
$T{"one"}{"two"} = "1" x 200000000;
system("vmstat 1 2");
So what I'm doing above is I'm creating an associative array %T,
then I'm doing the unix command "vmstat" which shows you how much
memory is free at the system level. Then I'm filling up the
associative array with 200MB of characters, basically just gulping
up a large amount of memory. Next, I display "vmstat" again. The
vmstat output should reflect the fact that I've just grabbed up
200MB of memory, and it does. Next, I supposedly free up the
memory by doing "%T = ();". Next, I do vmstat again, and it
displays that I'm still using 200MB. But this is perfectly normal
and expected, since I don't get that back until the program
exits. But what isn't normal or expected is what happens next...
Next, I grab another 200MB and store it in my associative array.
When I now do vmstat, it should not show any additional memory
usage, since it should just use the same memory address space
of the original gulp of 200MB. Instead, vmstat shows I just grabbed
up a lot more memory. So instead of just 200MB being used at this
point, it's actually using 400MB. It's like it didn't free up the
associative array's memory like I asked it to do.
As the script continues, it's supposed to free up the memory we just
grabbed and then grab another gulp of 200MB. But at no time in the
program should I be using any more than 200MB of memory. So, why is
it that when I run this script using some versions of perl5 do I see
the memory being drained as it goes through the script, eventually
running out of memory?
It's as if the garbage collection algorithm is not being run.
Seems like a HUGE bug to me!!!
I've tried this script on Linux, Solaris 2.6, and Solaris 2.7. It
seems independent of OS type. I've tried it on Perl versions 5.6.0,
5.005_03, and 5.00401. All those versions show the same bug. But
when I use version 5.003, it doesn't show the bug and behaves as
I would expect (correctly). So Perl version 5.003 is the only version
I've seen which doesn't have this bug.
Here's the output of my script running on Perl 5.6.0. It actually
shows that I run out of memory. Remember that in solaris, vmstat's
first output line is junk. So only look at the second output line:
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 1280 736 0 31 5 3 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 11 5697480 1794264 0 4 0 0 0 0 0 0 0 0 0 302 94 72 0 0 100
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 1296 736 0 31 5 3 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 11 4648296 817072 0 4 0 0 0 0 0 0 17 0 0 338 118 103 0 4 96
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 1296 736 0 31 5 3 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 11 4648296 817072 0 4 0 0 0 0 0 0 0 0 0 304 172 85 0 0 100
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 1304 744 0 31 5 3 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 11 4124008 328776 0 5 8 0 0 0 0 0 52 0 0 462 118 164 0 2 98
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 1304 744 0 31 5 3 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 11 4124008 328776 0 4 0 0 0 0 0 0 0 0 0 300 83 56 0 0 100
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 1320 744 0 31 5 4 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 11 3604768 31408 0 5 0 256 264 0 33 0 20 0 0 344 83 102 0 5 94
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 1320 744 0 31 5 4 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 11 3604752 31656 0 4 0 0 0 0 0 0 0 0 0 300 118 66 0 0 100
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 1384 744 0 31 5 4 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 11 3080008 64040 0 19 120 0 0 0 0 0 15 0 0 345 116 98 0 2 98
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 1384 744 0 31 5 4 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 11 3079992 64024 0 4 0 0 0 0 0 0 0 0 0 301 130 68 0 0 100
Out of memory during "large" request for 536875008 bytes at ./testthis3.pl line 30.
Notice how it was grabbing continually more and more memory from the
system. Bad !!
Here's the run on Perl 5.003:
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 3200 1304 0 31 5 4 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 28 5707752 1821120 0 4 0 0 0 0 0 0 0 0 0 301 83 55 0 0 100
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 3208 1312 0 31 5 4 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 28 4659168 844544 0 5 8 0 0 0 0 0 1 0 0 307 125 95 0 2 97
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 3208 1312 0 31 5 4 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 28 4659168 844544 0 4 0 0 0 0 0 0 0 0 0 300 83 52 0 0 100
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 3216 1312 0 31 5 4 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 28 4659168 844544 0 4 0 0 0 0 0 0 0 0 0 300 118 65 0 0 100
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr f0 s0 -- -- in sy cs us sy id
0 0 0 3216 1312 0 31 5 4 4 0 0 0 1 0 0 320 291 95 6 1 93
0 0 28 4659168 844544 0 4 0 0 0 0 0 0 0 0 0 300 147 67 0 0 100
..etc.
As you can see, in this version of Perl (5.003), it behaves correctly.
Vmstat shows that the memory is gulped up once during the beginning of
the program's run, but no additional memory is gulped up as the program
continues. And the program completes without an out-of-memory error.
Has anyone seen this before? Is there anything I can do to fix this?
Is there a compile-time option I can use? Is there a more up to date
version of Perl5 I can use?
This looks like a rather large bug. I work in the VLSI industry. We
use Perl scripts for just about everything, and our database sizes
are huge. Something like this is enough to make us start switching
to other languages.
Thanks,
- Steve Weigand
-------------------------------------------------------------------------
NOTE: To reply to me, remove "DONTMESSWITH" from my email address.
-------------------------------------------------------------------------
------------------------------
Date: Tue, 07 Aug 2001 03:40:08 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Perl5 memory leak or garbage collection problems?
Message-Id: <sqJb7.2688$nb4.180861@newsread1.prod.itd.earthlink.net>
<weigand@DONTMESSWITHtexas.net> wrote in message
news:JXHb7.115528$Cu6.8899914@bin3.nnrp.aus1.giganews.com...
> I've discovered a MAJOR bug in some Perl 5 builds, including the
> latest one it looks like. The problem has to do with the way Perl
> does garbage collection. Here's an example program to be run on
> Linux, Solaris, or other unices:
Great. Use perlbug to report it. I'm sure p5p will take care of it.
--Brent Dax
brentdax1@earthlink.net
------------------------------
Date: Tue, 07 Aug 2001 02:27:59 GMT
From: "Billy \"Bob\" Bob" <billy_dont_try@verizon.net>
Subject: Re: prompting and redirection with ssh
Message-Id: <s8jumto9raotmfsfr59jvofsffs8t0ekfu@4ax.com>
On Mon, 6 Aug 2001 23:46:14 +0000 (UTC), see-sig@from.invalid (David
Efflandt) wrote:
>On Mon, 06 Aug 2001, Billy \"Bob\" Bob <billy_dont_try@verizon.net> wrote:
>> I tried this, and it worked like you showed. However, what happens if
>> I redirect the output? When redirected I would like the prompt to
>> show up to the user, but what they type to show up in the redirected
>> file. I probably wasn't very clear on this in my original post. For
>> example:
>>
>> $ ssh -t mainpc ./input.pl > a
>> Prompt on /dev/pts/1
>> Feed me: It works!
>> $ cat a
>> You entered: It works!
>
>My mistake for not understanding about the redirection because of the tty
>thing. Output the prompt to STDERR instead of STDOUT (STDIN is still
>STDIN) and just print the final ouput to STDOUT:
>
>#!/usr/bin/perl -w
>use strict;
>my($reply);
>$| = 1;
>print STDERR "Feed me: ";
>if (defined($reply = <STDIN>)) { chomp $reply; } # single line
># while (defined($_ = <STDIN>)) { $reply .= $_; } # multiline
>if ($reply) {
> print "You entered: $reply\n";
>} else {
> print "No input received\n";
>}
>
>> ssh mainpc ./input2.pl > a
>Feed me: Is this what you want?
>> cat a
>You entered: Is this what you want?
You know, I don't think I tried that. I should have. Thanx for the
suggestion.
It's most interesting. It does work with ssh if I don't put the "-t"
switch. However, with "-t" it doesn't. oh the joy...:)
------------------------------
Date: Tue, 07 Aug 2001 04:42:28 +0200
From: gimi <gimi@psico.ch>
Subject: Re: q: launching a perl script from a perl script
Message-Id: <3B6F5594.49992209@psico.ch>
hi
Oliver wrote:
> /cgi-bin/x.cgi:
> #!/usr/bin/perl -w
> print ("x");
>
> (chmod 755 x.cgi)
well..
> x.html:
> <a href="/cgi-bin/x.cgi">x</a>
of course, this is
<html bla bla><head>bla bla</head><body>
<a href="/cgi-bin/x.cgi">x</a>
</body></html>
oh, and if your server runs perl, you can
<!--#exec cgi="/cgi-bin/x.cgi"-->
hth
gimi
--
http://www.psico.ch/
------------------------------
Date: Tue, 07 Aug 2001 04:43:17 +0200
From: gimi <gimi@psico.ch>
Subject: Re: q: launching a perl script from a perl script
Message-Id: <3B6F55C5.54CA07CD@psico.ch>
Oliver wrote:
> yea im obviously missing somthing really basic because i have now
[snip]
> "Brent Dax" <brentdax1@earthlink.net> wrote in message
[snip]
www.learn.to/quote
SCNR
--
http://www.psico.ch/
------------------------------
Date: Tue, 07 Aug 2001 02:05:19 GMT
From: Dan Baker <dan@nospam_dtbakerprojects.com>
Subject: Re: Sending e-mail from a script in MS windows
Message-Id: <3B6F4D25.1CC7A5A5@nospam_dtbakerprojects.com>
Martien Verbruggen wrote:
> > hhhmmm, last I tested, it did NOT work when sending from a win32
> > (windows98) machine running a localhost.
>
> What does this mean? 'Running a localhost'? Every TCP/IP implementation
> AFAIK has a 'localhost'...
-------
meaning I tried sending mail fired up from a script that was executed
from a webpage running on http://localhost. I use Xitami running on my
PCs at home to develop/test on, and there are a few things that seem to
work a little differently in conjunction with running ActivePerl and a
local web server on windows98 versus remote on a "regular" UNIX or LINUX
host. In this case I think I remember its because MIME::Lite doen't have
sendmail under the covers in the win32 port so its a little more
limited. Unless I read the docs and examples wrong, which is possible,
then there are several feaures that are not available when running on
win32.
>
> What didn't work? Any errors? At what point did it stop working?
-------
This was a while ago.... I don't remember any error messages, just that
CC and BCC addresses never got sent any mail in my tests. In the
specific case I was doing I only needed to send to 2 addresses, so i
just looped and didn't spend any more time trying to figure it out.
>
> Are you sure that you had your MTA set up correctly?
-------
I dunno, what's an MTA ? pardon the ignorance. I guess now I'm inspired
to get to the bottom of it and re-test and maybe figure this out...
Dan
------------------------------
Date: 06 Aug 2001 20:17:58 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Trouble Finding Parse::RecDescent for Perl 5.004
Message-Id: <m1vgk0sgm1.fsf@halfdome.holdit.com>
>>>>> "Bart" == Bart Lateur <bart.lateur@skynet.be> writes:
Bart> Oh great. That's a help if you want to run this on a Mac. Yes, indeed,
Bart> MacPerl's latest version is 5.004 (5.6.1 is in alpha).
But the current version of P::RD runs just fine on 5.004, because "the
Damian" uses (old stable) MacPerl to develop it! The version that
won't be out "until christmas" will use m//gc, and that will require
5.5 or better, but that has to wait until there's a good stable 5.6
macperl. :)
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Mon, 6 Aug 2001 20:22:27 -0600
From: "Richard A. Evans" <EvR@compuserve.com>
Subject: Re: validate IP address
Message-Id: <9knjf5$2ns$1@suaar1aa.prod.compuserve.com>
> You're missing that the from xxx.xxx.xxx.xx is not the only valid form for
> ip addresses.
I was responding to the comments that said:
If you mean valid as in "correct number of numbers", a short regular
expression will do the trick:
$ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
# make sure you have four digit sequences 1-3 numbers each, separated by
periods,
# and that the IP takes up the entire variable
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.
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 V10 Issue 1456
***************************************