[23775] in Perl-Users-Digest
Perl-Users Digest, Issue: 5979 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 24 21:05:40 2003
Date: Wed, 24 Dec 2003 18:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 24 Dec 2003 Volume: 10 Number: 5979
Today's topics:
Re: Accounting, Database Problem <nospam.hciss@yahoo.com>
Re: Install Perl module on Windows <rene.larsen@spamfilter.dk>
Re: LWP with proxy problem (Kevin Collins)
Re: LWP with proxy problem (Kevin Collins)
Re: Parsing File (Sara)
Problem with executing UNIX command in perl script (sunil)
Re: Problem with executing UNIX command in perl script <joost@rot13-ubeghf-zrpunavphf-rot13.net>
Re: Slow script <yshtil@cisco.com>
Re: Slow script <bobx@linuxmail.org>
Re: Slow script <DSX@comcast.net>
Re: Slow script <uri@stemsystems.com>
Re: Slow script <uri@stemsystems.com>
Re: Slow script <tore@aursand.no>
Re: Slow script <yshtil@cisco.com>
Re: Why chop fails? <DSX@comcast.net>
Re: Why chop fails? <krahnj@acm.org>
Re: Why does Perl use more resource than Php? <jundy@jundy.com>
Re: Why does Perl use more resource than Php? <tim@vegeta.ath.cx>
Re: Why does Perl use more resource than Php? <tim@vegeta.ath.cx>
Re: Why does Perl use more resource than Php? <noreply@gunnar.cc>
why this code shots up memory usage <a_madhur@vsnl.net>
Re: why this code shots up memory usage <sbryce@singlepoint.net>
Re: why this code shots up memory usage (Jay Tilton)
Re: why this code shots up memory usage <krahnj@acm.org>
Re: would someone tell me why this didn't work? <krahnj@acm.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 24 Dec 2003 15:23:45 -0600
From: "Matt" <nospam.hciss@yahoo.com>
Subject: Re: Accounting, Database Problem
Message-Id: <vuk0vt12bki0fc@corp.supernews.com>
> Perhaps you misunderstood:
>
> "I don't think file locking will be an issue"
>
> "tieing" to a file and "locking" a file are entirely different things.
> Locking is used to gain exclusive use of a file, or to methodically
> share it with other users.
No, I think I understood. I actually found examples of tieing. But after
further thought I may run into a locking issue. The primary script will be
the ONLY one to write to the file. I will have other scripts that read data
basically to get all the stats out but the will not change anything. The
thing I wonder about now is the scripts that read will also likely use
tieing. Even though they do not write will that create a problem if its
updated right from under it? I do not care if the reading script gets data
a little old.
After thinking if over using hash of arrays and tieing it to a file seems
the best way to do this. I just cannot find many examples of hashes of
arrays. My guides are: "Learning Perl" and "Perl Cookbook". Both quite
good I think.
What I think this needs laid out like. Hash containing around 200 entries
which will vary. Each entry contains an array of 672 numbers. Every hour I
will add another number to the end of each array and delete the oldest
value.
Matt
> Tie-ing, on the other hand, creates a realtime association between an
> Perl Varaiable (scalar, array, and perhaps most often a hash) and a
> special kind of file(s) created by the program itself. Since the file
> persists after the program executes, so does the associated var.
>
> But they are definitely NOT the same thing.
>
> G
------------------------------
Date: Wed, 24 Dec 2003 20:32:28 +0100
From: René Larsen <rene.larsen@spamfilter.dk>
Subject: Re: Install Perl module on Windows
Message-Id: <VA.00000005.0023a435@spamfilter.dk>
In article <3fe94069$0$1158$636a55ce@news.free.fr>, wrote:
>
> Hello,
>
> I need to add a few PERL modules to my ActivePerl 5.6.1 distribution.
> Some of them require a c-compiler
> Since my hosts are not dev stations, they don't have any C-compiler.
>
> Could you please advise me for a "light weight" c-compiler which could
> be easyly installed before perl modules ?
You need the same compiler, that ActivePerl is built with (I think it is
Visual C from MS).
If the Perl packages are available from ActiveState, you should use PPM
instead of CPAN.
Others may have built the package, e.g. R. Kobes (his repository is at:
<URL:http://theoryx5.uwinnipeg.ca/ppmpackages/>)
Regards, René
------------------------------
Date: 24 Dec 2003 11:21:22 -0800
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: LWP with proxy problem
Message-Id: <a6882f32.0312241121.1c3d3b46@posting.google.com>
genericax@hotmail.com (Sara) wrote in message news:<776e0325.0312240559.613c4dd4@posting.google.com>...
> kent_zunker@bmc.com (Woogie) wrote in message news:<4a31f52f.0312231243.25828446@posting.google.com>...
> > When running the sample code below without a proxy the GET returns the
> > expected data. When run with the $proxy uncommented the GET returns
> > the content of the login page for the site being accessed. The site
> > in the code is valid for ease of testing. I also am including the LWP
> > debug info for each attempt.
> >
> > Can anyone explain this behavior and what can I do to correct it?
> >
> > Thanks in advance
> >
-snip-
>
> might want to try on one of the cgi groups or even comp.perl.modules ?
Why? This has nothing (necessarily) to do with CGI. CGI is for web
clients and web servers talking to each other. And although LWP is
actually a web client, the example code does not appear related to any
CGI...
Kevin
------------------------------
Date: 24 Dec 2003 11:32:58 -0800
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: LWP with proxy problem
Message-Id: <a6882f32.0312241132.55fb4a0f@posting.google.com>
kent_zunker@bmc.com (Woogie) wrote in message news:<4a31f52f.0312231243.25828446@posting.google.com>...
> When running the sample code below without a proxy the GET returns the
> expected data. When run with the $proxy uncommented the GET returns
> the content of the login page for the site being accessed. The site
> in the code is valid for ease of testing. I also am including the LWP
> debug info for each attempt.
>
> Can anyone explain this behavior and what can I do to correct it?
>
> Thanks in advance
>
> Trace without proxy:
>
> LWP::UserAgent::new: ()
> LWP::UserAgent::request: ()
> LWP::UserAgent::send_request: GET
> https://squid.servebeer.com/getservices.do?user=Guest&password=JustLooking&format=csv
> LWP::UserAgent::_need_proxy: Not proxied
> LWP::Protocol::http::request: ()
> LWP::Protocol::collect: read 28 bytes
> LWP::UserAgent::request: Simple response: OK
>
> Home
> PE
>
>
> Trace with proxy:
>
> LWP::UserAgent::new: ()
> LWP::UserAgent::proxy: https http://148.245.207.85:8080
> LWP::UserAgent::request: ()
> LWP::UserAgent::send_request: GET
> https://squid.servebeer.com/getservices.do?user=Guest&password=JustLooking&format=csv
> LWP::UserAgent::_need_proxy: Proxied to http://148.245.207.85:8080
> LWP::Protocol::http::request: ()
> LWP::Protocol::collect: read 236 bytes
> LWP::Protocol::collect: read 594 bytes
> LWP::Protocol::collect: read 416 bytes
> LWP::Protocol::collect: read 450 bytes
> LWP::Protocol::collect: read 1017 bytes
> LWP::Protocol::collect: read 443 bytes
> LWP::Protocol::collect: read 643 bytes
> LWP::UserAgent::request: Simple response: OK
>
> <html lang="en">
>
> <!-- Start Head -->
> <head>
> <title>
>
> Error
>
> </title>
> <script language="JavaScript">
> ...
>
>
>
> Here is the sample code:
>
>
> #!/usr/bin/perl -w
>
> use LWP::UserAgent;
> use HTTP::Request;
> use HTTP::Response;
> use Crypt::SSLeay;
>
> LWP::Debug::level('+');
>
> $url = "https://squid.servebeer.com/getservices.do?user=Guest&password=JustLooking&format=csv";
> #$proxy="http://xxx.xxx.xxx.xxx:8080";
>
> $ua = LWP::UserAgent->new();
>
> if (defined $proxy)
> {
> $ENV{HTTPS_PROXY} = $proxy;
>
> # initialize from environment variables
> $ua->env_proxy;
> }
>
> $req = HTTP::Request->new(GET => $url);
> $response = $ua->request($req);
> if ($response->is_error())
> {
> printf " %s\n", $response->status_line;
> }
>
> else
> {
> $content = $response->content();
> print $content;
> }
>
> exit;
Your code has the definition of $proxy commented out, so I am not sure
your example is relevant to your output.
BUT, if it were uncommented, you are not including the ID and password
in the proxy URL (as you are in the "real" URL), so it makes some
sense that are being prompted for it.
Additionally, why do you want to redirect your request through a proxy
when you can get to it directly?
Kevin
------------------------------
Date: 24 Dec 2003 12:06:48 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: Parsing File
Message-Id: <776e0325.0312241206.5b462f94@posting.google.com>
James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<20031222125042.661d02e6.jwillmore@remove.adelphia.net>...
> On 22 Dec 2003 07:37:19 -0800
> genericax@hotmail.com (Sara) wrote:
> > tartemp@epix.net (BrokenSaint) wrote in message
> > news:<24813030.0312201921.3708d8f0@posting.google.com>...
>
> > die "duuuh gee Tenessee it wont even open!\n"
> > unless open F, 'myBigoleFile.dat';
>
> You *really* mean
>
> my $filename = '/path/name_of_file';
> open F, "$filename" or die "Can't open $filename: $!\n";
>
> right?
>
> I realize that it's good to throw some humor into code (believe it or
> not), but not at the expense of knowing what happened. I mean, if you
> want to have a list of codes related to what happened, be my guest.
> However, I enjoy the fact that I can put something into the error
> statements that say *exactly* what's going on. I'm thinking others do
> too :-)
>
> And why 'unless'? Please, explain *why* you check 'open' in such a
> way. It's more efficent to try and open the file first, *then* die if
> you can't.
>
> However, maybe you know something I don't - and if that's the case,
> please enlighten me (and others) in the error of our ways ;-)
>
Jim, this may not be obvious, but when you think about it- it should
be. How could the script "die" then "open a file"? Its really the same
thing as
unless (open) {die;}
without all of the ugly parens and {}'s cluttering up the landscape.
They two probably compile to about the same result.
This is a little idiomatic niciety from Larry (remember Larry is a
linguist!), and for me I lke the way it reads. I know the Camel Style
pages say this isn't such a nifty idiom, but I like it, its easily
read, and it works. And as long as those poor Compiler-writers (aka
Chip?) have to deal with this non LLR construct, well by golly we
ought to put their efforts to good use!
As for the spelling of "Tenessee", how well do you think a Walrus
spells? Some of our readers really need to get those chips off their
shoulders..
Happy Holiday!
G
> --
> Jim
>
------------------------------
Date: 24 Dec 2003 17:47:36 -0800
From: sunilsreenivas2001@yahoo.com (sunil)
Subject: Problem with executing UNIX command in perl script
Message-Id: <d924fa71.0312241747.6583b441@posting.google.com>
Hi All,
I am trying to execute a complex piped UNIX command in perl
script as follows:
system("nm @ARGV | awk -F\| '$4 == "OBJT " && $5 == "GLOB " {print $8
" " $3}'| grep '^[^$]' | uniq | sort -r | awk '$1 != prevvar
{varstr=sprintf("char %s[%d];",$1,$2);print varstr;prevvar = $1}' |
sort > $ofname");
and it fails with many errors. The errors are compile time errors and
more problems than that. awk uses $0,$1 and I noticed that perl may
substitute its own values for $1....
I tried to get information from PERL documentation and it says that if
I pass entire command and argument list as single scalar (which I am
doing), if there are any shell metacharacters (there are in current
case) it is passed to shell for parsing. Hence it should be able to
execute this.
Any pointers to documentation which can give me more insight into this
or any help will be greatly appreciated.
Thanks,
Sunil.
------------------------------
Date: Thu, 25 Dec 2003 03:05:33 +0100
From: "Joost Diepenmaat" <joost@rot13-ubeghf-zrpunavphf-rot13.net>
Subject: Re: Problem with executing UNIX command in perl script
Message-Id: <pan.2003.12.25.02.05.33.181980@rot13-ubeghf-zrpunavphf-rot13.net>
On Wed, 24 Dec 2003 17:47:36 -0800, sunil wrote:
> Hi All,
> I am trying to execute a complex piped UNIX command in perl
> script as follows:
>
> system("nm @ARGV | awk -F\| '$4 == "OBJT " && $5 == "GLOB " {print $8 " "
> $3}'| grep '^[^$]' | uniq | sort -r | awk '$1 != prevvar
> {varstr=sprintf("char %s[%d];",$1,$2);print varstr;prevvar = $1}' | sort >
> $ofname");
>
> and it fails with many errors. The errors are compile time errors and more
> problems than that. awk uses $0,$1 and I noticed that perl may substitute
> its own values for $1....
> I tried to get information from PERL documentation and it says that if I
> pass entire command and argument list as single scalar (which I am doing),
> if there are any shell metacharacters (there are in current case) it is
> passed to shell for parsing. Hence it should be able to execute this.
> Any pointers to documentation which can give me more insight into this or
> any help will be greatly appreciated. Thanks,
> Sunil.
You are using a literal " character in a "-delimited string, for one. Also
note that using a "-delimited string will interpolate Perl variables typed
in the string literal.
To combat all of this use something like (untested):
system q[m @ARGV | awk -F\| '$4 == "OBJT " && $5 == "GLOB " {print $8 " "
$3}'| grep '^[^$]' | uniq | sort -r | awk '$1 != prevvar
{varstr=sprintf("char %s[%d];",$1,$2);print varstr;prevvar = $1}' | sort >
$ofname];
where the q[ ... ] construct is equivalent to ' ... ' (that is,
uninterpolated string), but doesn't get confused by your use of '
characters in the string literal.
look for qq and q in "perldoc perlop" for more info.
HTH
--
Joost Diepenmaat
There are rot13's in my address. Remove them and apply one to mail me.
------------------------------
Date: Wed, 24 Dec 2003 12:05:46 -0800
From: Yuri Shtil <yshtil@cisco.com>
Subject: Re: Slow script
Message-Id: <3FE9F19A.3020105@cisco.com>
Well, I take it as a joke.
Seriously, are there any known issues that cause legacy code run slower
under 5.8 ?
Uri Guttman wrote:
>>>>>>"YS" == Yuri Shtil <yshtil@cisco.com> writes:
>>>>>
>
> > I have a script I inherited that was developed under perl 5.004.
>
> > I tried to run it under perl 5.8.0. It runs much much slower.
> > There is a lot of regular expressions that are invoked.
>
> > Any idea anyone why this might be happening?
>
> line 42 is written poorly.
>
> uri
>
------------------------------
Date: Wed, 24 Dec 2003 20:38:47 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: Slow script
Message-Id: <rPmGb.1944$zC4.2122077@news2.news.adelphia.net>
"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x765g6hwcv.fsf@mail.sysarch.com...
> >>>>> "YS" == Yuri Shtil <yshtil@cisco.com> writes:
>
> > I have a script I inherited that was developed under perl 5.004.
>
> > I tried to run it under perl 5.8.0. It runs much much slower.
> > There is a lot of regular expressions that are invoked.
>
> > Any idea anyone why this might be happening?
>
> line 42 is written poorly.
>
> uri
>
> --
Are you sure? I thought it might be the loop in lines 54-64? ; )
------------------------------
Date: Wed, 24 Dec 2003 22:05:12 GMT
From: "Nick Santos" <DSX@comcast.net>
Subject: Re: Slow script
Message-Id: <s4oGb.471552$275.1369081@attbi_s53>
"Yuri Shtil" <yshtil@cisco.com> wrote in message
news:3FE9D92C.2070704@cisco.com...
> Hi
>
> I have a script I inherited that was developed under perl 5.004.
>
> I tried to run it under perl 5.8.0. It runs much much slower.
> There is a lot of regular expressions that are invoked.
>
> Any idea anyone why this might be happening?
>
> Yuri.
>
jokes aside, I have heard some rumors that perl 5.8 is much slower than
previous releases. Not sure how valid it is, but I think some benchmarks
have shown it (sorry, couldn't link you). So, I don't know if it's
necessarily that it has lots of regular expressions, but more that it just
has code at all and is running on 5.8
-Nick
------------------------------
Date: Wed, 24 Dec 2003 22:35:38 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Slow script
Message-Id: <x7smj9hmiu.fsf@mail.sysarch.com>
>>>>> "BX" == Bob X <bobx@linuxmail.org> writes:
> "Uri Guttman" <uri@stemsystems.com> wrote in message
> news:x765g6hwcv.fsf@mail.sysarch.com...
>> >>>>> "YS" == Yuri Shtil <yshtil@cisco.com> writes:
>>
>> > I have a script I inherited that was developed under perl 5.004.
>>
>> > I tried to run it under perl 5.8.0. It runs much much slower.
>> > There is a lot of regular expressions that are invoked.
>>
>> > Any idea anyone why this might be happening?
>>
>> line 42 is written poorly.
>>
>> uri
>>
>> --
> Are you sure? I thought it might be the loop in lines 54-64? ; )
RTFM.
use PSI::ESP and it tells you the slow line numbers. i can't believe you
made a random guess like that. sheesh!!
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Wed, 24 Dec 2003 22:37:46 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Slow script
Message-Id: <x7ptedhmf9.fsf@mail.sysarch.com>
>>>>> "YS" == Yuri Shtil <yshtil@cisco.com> writes:
<you stealth emailed me. please don't do that. and you top posted as
well. read the group guidelines>
> Well, I take it as a joke.
> Seriously, are there any known issues that cause legacy code run
> slower under 5.8 ?
i have no clue about that. you should run them under a profiler and see
where the speed changes are most noticeble. then you can optimize that
particular area. and if you are using lots of regular expressions, there
are techniques to make them run faster. but since you posted no code, we
can't help you.
<snip of TOFU>
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 25 Dec 2003 00:56:28 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Slow script
Message-Id: <pan.2003.12.24.22.30.08.328644@aursand.no>
On Wed, 24 Dec 2003 10:21:32 -0800, Yuri Shtil wrote:
> I have a script I inherited that was developed under perl 5.004.
>
> I tried to run it under perl 5.8.0. It runs much much slower. There is a
> lot of regular expressions that are invoked.
>
> Any idea anyone why this might be happening?
The jokes that have been posted _have_ a valid point; you should post the
code you're referring to.
On the other hand: I've never benchmarked 5.0xx against any of the other
versions, but _for me_ version 5.8.2 was quite a lot faster than 5.8.0.
That might be because I compiled 5.8.2 myself, while 5.8.0 came
pre-installed with Red Hat 9.0. One _simple_ benchmark showed that the
same script was _twice_ as fast in 5.8.2 compared to 5.8.0.
--
Tore Aursand <tore@aursand.no>
"Out of missiles. Out of bullets. Down to harsh language." -- Unknown
------------------------------
Date: Wed, 24 Dec 2003 16:05:32 -0800
From: Yuri Shtil <yshtil@cisco.com>
Subject: Re: Slow script
Message-Id: <3FEA29CC.6000806@cisco.com>
The reason I did not post the code is that it is quite large and only
works in a specific environment. I did not expect folks here to pinpoint
a problem in the code. My point was that the code runs about 5 times
slower under 5.8.0 than under 5.004. I thought that maybe this was a
known issue with 5.8.0. I apologise if my question was not asked correctly.
Tore Aursand wrote:
> On Wed, 24 Dec 2003 10:21:32 -0800, Yuri Shtil wrote:
>
>>I have a script I inherited that was developed under perl 5.004.
>>
>>I tried to run it under perl 5.8.0. It runs much much slower. There is a
>>lot of regular expressions that are invoked.
>>
>>Any idea anyone why this might be happening?
>
>
> The jokes that have been posted _have_ a valid point; you should post the
> code you're referring to.
>
> On the other hand: I've never benchmarked 5.0xx against any of the other
> versions, but _for me_ version 5.8.2 was quite a lot faster than 5.8.0.
>
> That might be because I compiled 5.8.2 myself, while 5.8.0 came
> pre-installed with Red Hat 9.0. One _simple_ benchmark showed that the
> same script was _twice_ as fast in 5.8.2 compared to 5.8.0.
>
>
------------------------------
Date: Wed, 24 Dec 2003 22:09:06 GMT
From: "Nick Santos" <DSX@comcast.net>
Subject: Re: Why chop fails?
Message-Id: <68oGb.193044$_M.875511@attbi_s54>
"Huey" <huey_jiang@yahoo.com> wrote in message
news:ae92bb50.0312240742.dc8da57@posting.google.com...
> Hi All,
>
> Merry Xmas! I wonder somebody would work at this moment, but this
> simple problem just drives me nuts! How can a chop function fail? I
> simply read from a text file, and need to clean up the newline char
> with chop, but failed! My simply code:
>
> #!perl
> # records in file foo.txt is like "me:123\n"
> open (F, "./foo.txt");
> while (<F>) {
> ($u, $p) = split(/:/, $_);
> chop $p;
> if ( $p eq "123" ) {
> print "got ya!", "\n";
> }
> }
> close(F);
>
> I am using cygwin perl. I noticed $p looked correct in command-line
> when printed. The problem is the if () test never go true, it means
> that $p never equals "123", and chop never worked! Aha! Funny? Anybody
> ever experienced such a thing? Please give me your solution, thanks a
> lot!
>
> Huey
I agree. Always use chomp for newline, because it will only delete the
newline character and then if for some odd reason you don't actually have a
newline, you aren't deleting necessary parts of your string.
------------------------------
Date: Wed, 24 Dec 2003 23:36:13 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Why chop fails?
Message-Id: <3FEA22CC.D37E1FAE@acm.org>
Huey wrote:
>
> Merry Xmas! I wonder somebody would work at this moment, but this
> simple problem just drives me nuts! How can a chop function fail? I
> simply read from a text file, and need to clean up the newline char
> with chop, but failed! My simply code:
>
> #!perl
> # records in file foo.txt is like "me:123\n"
> open (F, "./foo.txt");
You should _ALWAYS_ verify that the file opened correctly.
open F, 'foo.txt' or die "Cannot open 'foo.txt' $!";
> while (<F>) {
> ($u, $p) = split(/:/, $_);
> chop $p;
You should use chomp() instead of chop().
chomp;
( $u, $p ) = split/:/;
> if ( $p eq "123" ) {
You should use a numerical comparison operator to compare numbers.
if ( $p == 123 ) {
> print "got ya!", "\n";
> }
> }
> close(F);
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 24 Dec 2003 20:18:08 GMT
From: Erik Tank <jundy@jundy.com>
Subject: Re: Why does Perl use more resource than Php?
Message-Id: <3e271181916e651ec1327a69902a1a3c@news.teranews.com>
Your arguement doesn't really make sense. I can write two programs
(both in Perl) that do exactly the same thing and one will run like
lightening with nearly no impact on the machine while the other will
grind the machine to a halt eventually crashing it.
Neither outcome is Perl's fault - it is the fault of the programmer
who either wrote inteligent/effecient code verses code that has memory
leaks, hogs resources, etc.
Asking if Perl is slower or uses more resources that PHP is like
asking if a Ford gets better gas mileage than a Toyota.
On Wed, 24 Dec 2003 12:13:51 +0100, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
>Sam Holden wrote:
>> What that application is written in is irrelevant (if it was they
>> would ban that language and not just the application).
>
>I'm not following you, Sam. A Perl app that means a large number of
>new processes, which I suppose is the case with a bulletin board, may
>well reach the limit as regards how much CPU a web host accepts,
>without the host necessarily having to ban Perl for smaller
>applications. And there may be other languages that require less CPU
>for a similar app, so the language may well be relevant.
>
>(mod_perl is sometimes useful in cases like this, but very few web
>hosts offer that option.)
------------------------------
Date: 24 Dec 2003 21:29:02 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Why does Perl use more resource than Php?
Message-Id: <slrnbuk18m.aah.tim@vegeta.saiyix>
Erik Tank <jundy@jundy.com> wrote:
> Asking if Perl is slower or uses more resources that PHP is like
> asking if a Ford gets better gas mileage than a Toyota.
Except that IRL I'd buy a Toyota before a Ford[*], yet I'd write web
apps in C++ before I'd write them in PHP. :)
Aside from that, your analogy is sound, IMHO.
YMMV. In several senses. :)
[*] This is not an attack on American automobile quality. I'd drive
a Chevy before either of the above mentioned makes. And my own
car's make has yet to be mentioned. :)
Cheers!
Tim Hammerquist
--
Not all who wander are lost.
-- J.R.R. Tolkien
------------------------------
Date: 24 Dec 2003 21:49:15 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Why does Perl use more resource than Php?
Message-Id: <slrnbuk2ej.aah.tim@vegeta.saiyix>
Phil Roberts <philrob@HOLYflatnetSHIT.net> wrote:
> Perl is usually run as a CGI module which will consume more server
> RAM than a scripting interpreter which is running as part of the
> server process (as PHP almost always is).
Building Apache modules (such as mod_perl or mod_php) increases the
amount of required RAM just as executing a pure CGI process would.
The advantage of mod_* interpreters lies in reduced overhead:
- reduced script start-up time due to no additional processes being
created.
- increased performance for shared information: client apps can use
Perl and/or Apache API to exchange information with the server,
instead of having to rely on the standard environment/stdin/stdout
CGI interface.
Regardless of this, the amount RAM needed to run an
Apache/mod_perl/script-app is the sum total of the server itself
(httpd), the mod_perl module (mod_perl.so), and the size in RAM of the
compiled and running script itself.
That said, I've often been disappointed by PHP's relatively default
nature in web hosts, while Perl is only supported (if at all) as an
external CGI proc.
Cheers,
Tim Hammerquist
--
Not all who wander are lost.
-- J.R.R. Tolkien
------------------------------
Date: Thu, 25 Dec 2003 00:58:55 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Why does Perl use more resource than Php?
Message-Id: <bsd9d4$b3vdb$1@ID-184292.news.uni-berlin.de>
[ Please do not top post! ]
Erik Tank wrote:
> Gunnar Hjalmarsson wrote:
>> Sam Holden wrote:
>>> What that application is written in is irrelevant (if it was
>>> they would ban that language and not just the application).
>>
>> I'm not following you, Sam. A Perl app that means a large number
>> of new processes, which I suppose is the case with a bulletin
>> board, may well reach the limit as regards how much CPU a web
>> host accepts, without the host necessarily having to ban Perl for
>> smaller applications. And there may be other languages that
>> require less CPU for a similar app, so the language may well be
>> relevant.
>>
>> (mod_perl is sometimes useful in cases like this, but very few
>> web hosts offer that option.)
>
> Your arguement doesn't really make sense.
Now i'm confused. If you don't run your Perl program under mod_perl or
something similar, it's compiled every time it's called. The
compilation costs CPU. (Please correct me if I'm wrong so far.)
> I can write two programs (both in Perl) that do exactly the same
> thing and one will run like lightening with nearly no impact on the
> machine while the other will grind the machine to a halt eventually
> crashing it.
Of course. But you can't do anything about the need to compile.
> Asking if Perl is slower or uses more resources that PHP is like
> asking if a Ford gets better gas mileage than a Toyota.
The question in the subject line of this thread may not be possible to
answer. But for a particular application area I really thought is was
not only possible, but also advisable, to consider which programming
language is the better choice out from various viewpoints - also CPU
usage. If you guys disagree on that, I must have missed something.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 25 Dec 2003 01:05:31 +0530
From: "Madhur" <a_madhur@vsnl.net>
Subject: why this code shots up memory usage
Message-Id: <bscpp3$bi4iu$1@ID-81175.news.uni-berlin.de>
Hello
The following code snippet, shots the memory usage to full and
results in Out of Memory error.
The substitution seems to be the culprit. But why it happens. I
am running W2K, Perl 5.6.
@input=<MYFILE>;
$i=0;
while($i<=@input)
{
$input[$i]=~s/^[0-9]+://;
print("$input[$i]");
$i++;
}
close(MYFILE);
--
Winners dont do different things, they do things differently.
Madhur Ahuja
India
email : madhur<underscore>ahuja<at>yahoo<dot>com
------------------------------
Date: Wed, 24 Dec 2003 15:22:40 -0700
From: Scott Bryce <sbryce@singlepoint.net>
Subject: Re: why this code shots up memory usage
Message-Id: <3FEA11B0.8080207@singlepoint.net>
Madhur wrote:
> Hello
> The following code snippet, shots the memory usage to full and
> results in Out of Memory error.
> The substitution seems to be the culprit. But why it happens. I
> am running W2K, Perl 5.6.
>
> @input=<MYFILE>;
> $i=0;
> while($i<=@input)
> {
>
> $input[$i]=~s/^[0-9]+://;
> print("$input[$i]");
> $i++;
> }
> close(MYFILE);
It is because the line
$input[$i]=~s/^[0-9]+://;
keeps adding elements to the array after you have reached the end of the
data, so that
while($i<=@input)
always evaluates to true.
I think what you want is...
use strict;
use warnings;
open MYFILE, "<somefile.txt" or die "Cannot open somefile.txt -- $!\n";
while(<MYFILE>)
{
chomp;
s/^[0-9]+://;
print "$_\n";
}
close(MYFILE) or die "Cannot close somefile.txt -- $!\n";
------------------------------
Date: Wed, 24 Dec 2003 22:24:40 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: why this code shots up memory usage
Message-Id: <3fea1015.417939023@news.erols.com>
"Madhur" <a_madhur@vsnl.net> wrote:
: The following code snippet, shots the memory usage to full and
: results in Out of Memory error.
: The substitution seems to be the culprit. But why it happens. I
: am running W2K, Perl 5.6.
:
: @input=<MYFILE>;
: $i=0;
: while($i<=@input)
: {
:
: $input[$i]=~s/^[0-9]+://;
: print("$input[$i]");
: $i++;
: }
: close(MYFILE);
It happens because of autovivification. The s/// operation brings
$input[$i] into existence if it doesn't exist already. The loop will add
new elements to @input forever.
Change the condition either to:
while( $i < @input ) { ... }
or to:
while( $i <= $#input ) { ... }
or even better, completely ditch the index and directly iterate over the
array's elements:
for( @input ) {
s/^[0-9]+://;
print;
}
------------------------------
Date: Wed, 24 Dec 2003 23:29:44 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: why this code shots up memory usage
Message-Id: <3FEA2147.CC7BDC19@acm.org>
Madhur wrote:
>
> The following code snippet, shots the memory usage to full and
> results in Out of Memory error.
> The substitution seems to be the culprit. But why it happens. I
> am running W2K, Perl 5.6.
>
> @input=<MYFILE>;
You are reading the entire file into memory. If it is a large file then
this will die with an Out of Memory error.
> $i=0;
> while($i<=@input)
> {
>
> $input[$i]=~s/^[0-9]+://;
> print("$input[$i]");
> $i++;
> }
> close(MYFILE);
The usual way to write that in perl is:
while ( <MYFILE> ) {
s/^\d+://;
print;
}
close MYFILE;
Or another way: without the substitution:
while ( <MYFILE> ) {
print substr $_, 1 + index $_, ':';
}
close MYFILE;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 24 Dec 2003 23:15:59 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: would someone tell me why this didn't work?
Message-Id: <3FEA1E0D.8DDC3197@acm.org>
johnny wrote:
>
> I wrote a script to process text in a bunch of files.
> While working on it, I would test it on one file, just to
> see how it was going. BUT, when i tried to run it on all
> the input files, it wouldn't work. It would only do the
> first file found in the input directory. After I
> commented out "reset $t;" the script processed all files
> in the input directory.
reset() does not do what you seem to think it does and besides you are
declaring $t as a lexical variable so its scope it limited anyway.
perldoc -f reset
> What I don't understand is why ?????
> Come to think of it, I don't even remember why I put the
> line in there in the first place.
>
>
> #!/usr/bin/perl -w
> use strict;
> foreach (@ARGV) {
> my $infile = $_;
foreach my $infile ( @ARGV ) {
> print "Now parsing $infile\n";
> my $outfile = $infile;
> $outfile =~ s/lists/data/;
>
> open IN, '<'.$infile || die "Error: $!\n";
> open OUT, '>'.$outfile || die "Error: $!\n";
Your die() statements will never execute because of the higher precedece
of the || operator. Perl interprets these statements as:
open IN, ( '<'.$infile || die "Error: $!\n" );
open OUT, ( '>'.$outfile || die "Error: $!\n" );
You need to either enclose the open() function in parenthesis or use the
lower precedence 'or' operator.
> $/ = "\n\n";
> while(defined ( my $t = <IN>)) {
my() creates a new $t variable each time through the loop, it doesn't
have to be "reset."
> #do stuff here with $t
> $t =~ s/\n\t//g;
> $t =~ s/\t/ /g;
> my @card = split /\n/m,$t;
The /m option only applies if you are using the ^ or $ anchors in the
regex.
> foreach(@card) {
> print OUT $_."\n";
> if( $_ =~ /^Rar/) {
> print OUT "\n";
> }
> } #foreach(@card)
> #######################################
> ### THIS LINE HERE
> # reset $t;
> ### STUPID LINE x(
> #######################################
> } #while(defined (my $t = <IN>))
>
> close OUT;
> close IN;
> } #foreach(@ARGV)
You can use perl's built-in @ARGV processing to simplify this a bit:
#!/usr/bin/perl -w
use strict;
die "usage: $0 filename(s)\n" unless @ARGV;
$/ = "\n\n";
while ( <> ) {
if ( $. == 1 ) {
print "Now parsing $ARGV\n";
( my $outfile = $ARGV ) =~ s/lists/data/;
open OUT, '>' . $outfile or die "Error: $!\n";
}
#do stuff here with $_
s/\n\t//g;
tr/\t/ /;
s/^Rar.*//mg;
print OUT;
close ARGV if eof; # reset $.
}
__END__
John
--
use Perl;
program
fulfillment
------------------------------
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 5979
***************************************