[22101] in Perl-Users-Digest
Perl-Users Digest, Issue: 4323 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 30 09:06:48 2002
Date: Mon, 30 Dec 2002 06: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 Mon, 30 Dec 2002 Volume: 10 Number: 4323
Today's topics:
AWK vs PERL - splitting fields <Miguel.Duarte@tmn.pt>
Re: AWK vs PERL - splitting fields <mgjv@tradingpost.com.au>
Re: beginner: trying to dig in syslog <japie@nospam.org>
Re: C Backend <goldbb2@earthlink.net>
Charting/Graphs <robert.j.sipe@boeing.com>
Re: Charting/Graphs <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Re: Charting/Graphs <spam@thecouch.homeip.net>
Check FTP links with LWP:UserAgent <kuujinbo@yahoo.com>
Re: Devel::DProf giving bad results? (tî'pô)
Re: Palm::Datebook generated events disappearing! <usenet@ethanbrown.org>
Re: Parse HTTP RESPONSE Headers Active Perl CGI (Brian McCauley)
Sleep Until Key Press <blnukem@hotmail.com>
Re: Sleep Until Key Press (Anno Siegel)
use perl api from csh <sunil_franklin@hotmail.com>
Re: use perl api from csh (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 30 Dec 2002 11:11:36 +0000
From: Miguel Angelo Lapa Duarte <Miguel.Duarte@tmn.pt>
Subject: AWK vs PERL - splitting fields
Message-Id: <3e102783$0$765$a729d347@news.telepac.pt>
This is a multi-part message in MIME format.
--------------020107060506030809040900
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Once I argued whith an Un*x old timer at my company that perl was better
then awk. He told me that perl, although more flexible, could be
orders of magnitude slower than AWK while spliting fields.
I didn't believe him (never believe anything without trying it out
yourself) so I decided to do a small benchmark.
1- Generate a test file (attached generate.pl for your convenience)
---
for($l = 0; $l < $ARGV[0]; ++$l) {
for($c = 0; $c < $ARGV[1] - 1; ++$c) {
print int(rand(100)) . ',';
}
print int(rand(100));
print "\n";
}
---
perl generate.pl 100000 100 > test
Will generate a 100.000 line file, each line containing 100 columns of
random numbers.
2 - script to parse the file and print a random column
2.1- AWK
attached split.awk your convenience
---
BEGIN {
FS=","
}
{
print $randi(100);
}
function randi(n) {
return int(n * rand()) + 1;
}
----
2.2- PERL script
attached split.pl your convenience
----
@a = split(",");
print $a[rand(100)]."\n";
----
Benchmark
$ uname -a
Linux divvy900.tmn.pt 2.4.19-16mdk (...)
Benchmark AWK
$ gawk --version
GNU Awk 3.1.1
$ time gawk -f split.awk < test > /dev/null
0.81user 0.01system 0:00.81elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (189major+34minor)pagefaults 0swaps
$
Benchmark PERL
[miguel@divvy900 awk]$ perl --version
This is perl, v5.8.0 built for i386-linux-thread-multi
$ time perl -n split.pl < test > /dev/null
28.32user 0.02system 0:28.33elapsed 100%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (364major+69minor)pagefaults 0swaps
$
28.33s/0.84s=33.72 (Gawk was nearly 3372% faster)
Note: The system load was the same in the beggining of both benchmarks...
Is there any faster way of doing that on PERL ?
Thanks,
Miguel
--------------020107060506030809040900
Content-Type: text/plain;
name="generate.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="generate.pl"
for($l = 0; $l < $ARGV[0]; ++$l) {
for($c = 0; $c < $ARGV[1] - 1; ++$c) {
print int(rand(100)) . ',';
}
print int(rand(100));
print "\n";
}
--------------020107060506030809040900
Content-Type: text/plain;
name="split.awk"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="split.awk"
BEGIN {
FS=","
}
{
print $randi(100);
}
function randi(n) {
return int(n * rand()) + 1;
}
--------------020107060506030809040900
Content-Type: text/plain;
name="split.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="split.pl"
@a = split(",");
print $a[rand(100)]."\n";
--------------020107060506030809040900--
------------------------------
Date: Mon, 30 Dec 2002 22:51:55 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: AWK vs PERL - splitting fields
Message-Id: <slrnb10cqr.4tt.mgjv@martien.heliotrope.home>
On Mon, 30 Dec 2002 11:11:36 +0000,
Miguel Angelo Lapa Duarte <Miguel.Duarte@tmn.pt> wrote:
> This is a multi-part message in MIME format.
> --------------020107060506030809040900
> Content-Type: text/plain; charset=us-ascii; format=flowed
> Content-Transfer-Encoding: 7bit
>
> Once I argued whith an Un*x old timer at my company that perl was better
> then awk. He told me that perl, although more flexible, could be
> orders of magnitude slower than AWK while spliting fields.
He's right. And awk has other advantages over perl.
$ man perlvar
[snip]
Remember: the value of "$/" is a string, not a
regex. awk has to be better for something. :-)
[snip]
On the other hand, Perl is a full-fledged programming language, with
many features that awk doesn't have. It isn't possible to make a
one-on-one comparison. Perl started out as a replacement for awk, sed,
grep and some other tools, enhanced to be a programming language.
Nowadays, it is more a programming language than a replacement for those
tools. The flexibility and feature-richness comes at a price. Perl often
is slower than more specialised tools.
On the other hand, Perl's regular expressions are generally faster than
awks.
$ perl -ne 'print if /some_pattern/' < file
vs.
$ awk '/some_pattern/ { print }' < file
is probably slower. On the other hand,
$ grep 'some_pattern' < file
is likely to be faster.
One of awks primary tasks is splitting and such. One of greps primary
tasks is pattern matching on lines. When in their application domain,
these tools perform better than Perl. A pipeline of standard unix tools
is often a better choice than a Perl program or a perl one-liner. But I
would hesitate to come up with any blanket rules. Whatever works best
for the situation at hand is best. Learning to guess which tool will
perform best in which situations is the art.
> Is there any faster way of doing that on PERL ?
You could try something like:
$ perl -alnF, -e 'print $F[rand(100)]' < test > /dev/null
but I doubt it'll be much faster, if at all.
Martien
--
|
Martien Verbruggen | The Second Law of Thermodenial: In any closed
| mind the quantity of ignorance remains
| constant or increases.
------------------------------
Date: Mon, 30 Dec 2002 08:49:46 GMT
From: Japie <japie@nospam.org>
Subject: Re: beginner: trying to dig in syslog
Message-Id: <KMTP9.111$KF.31836@amsnews02.chello.com>
On Sun, 29 Dec 2002 20:04:16 +0100, Anno Siegel wrote:
> quality of the script you have there, which is way above average.
I will give your compliments to Gege.
> Noted. However, it is good practice to mark changes you have made to
> the original code, even trivial ones. There were (at least) two more
> places that should have been marked this way.
When posting I stripped all the coments to make it smaller :-O
> Quite a few tutorials are part of the Perl documentation (hence part of
> Perl) and locally available through the perldoc command. Start with
> "perldoc perl" for an overview and take it from there.
I can asure you I will start learning Perl next year, I will have more
time then. The only problem is I have trouble understanding most of the
docs. (that means hard work)
Viewing existing code is giving me more than what I've read so far in
docs. But perl looks great to me, it's logic, very much open source
(nothing to compile, so no secrets), possible to make subroutines and
there are even plugins to use a grafical toolkit!
Cool..
--
Best wiches for 2003, Japie.
------------------------------
Date: Mon, 30 Dec 2002 00:49:10 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: C Backend
Message-Id: <3E0FDE56.315D4491@earthlink.net>
Jeff Mott wrote:
>
> > How do you know that the 'print' operator in your current version of
> > perl gets compiled to the same numeric opcode as it did back in
> > 5.5.30?
>
> It's not a problem that it compiles into the wrong instructions, it's
> a problem that it doesn't compile at all.
When I said "compile", I meant parsed and turned into an in-memory tree
of opcodes. The B::CC module depends on this tree having a specific
form, and on the nodes in the tree being particular structures.
So with 5.5.30, your "print 'Hello World';" program might have parsed to
one type of tree of opcodes, and in 5.6.x, parse to a different tree.
The B::CC module doesn't look at perl source, it only looks at the tree.
So, if different versions of perl mean that your program produces
different optrees, then from B::CC's point of view, it's two different
programs.
> But, experimental or not, it must have been functional, at least in
> part, to have ever been released.
Try installing 5.5.30, and running it with that. Maybe it will be
functional.
> And I'm just trying to figure out why I can't get this to work at all.
Because it depends on the internals of how perl works, and the internals
have changed in a non-backward-compatible way.
> If you know how to get it working, please let me know. If you just
> feel like restating the problem again, feel free to keep it to
> yourself.
To make it work with perl 5.6.1, I would suggest you figure out how it
worked in the first place, and rewrite it.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Mon, 30 Dec 2002 04:48:27 GMT
From: Robert Sipe <robert.j.sipe@boeing.com>
Subject: Charting/Graphs
Message-Id: <3E0FD01B.382735D6@boeing.com>
I need to chart performance data I extract from an SNMP daemon. Thus, I
will periodically poll the system for a few performance values, store
the data to a file, then chart it out in on a Web page. I have the SNMP
polling and data collection all taken care of. It is simple graph of
perf data vs. time. What is the recommended module/method to
chart/graph this data using a cgi script? Thanx in advance!
------------------------------
Date: Mon, 30 Dec 2002 07:45:56 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: Charting/Graphs
Message-Id: <newscache$ks6x7h$s22$1@news.emea.compuware.com>
Robert Sipe wrote (Monday 30 December 2002 05:48):
> I need to chart performance data I extract from an SNMP daemon. Thus, I
> will periodically poll the system for a few performance values, store
> the data to a file, then chart it out in on a Web page. I have the SNMP
> polling and data collection all taken care of. It is simple graph of
> perf data vs. time. What is the recommended module/method to
> chart/graph this data using a cgi script? Thanx in advance!
http://search.cpan.org/search?query=chart
That was easy, wasn't it?
--
KP
------------------------------
Date: Mon, 30 Dec 2002 03:01:25 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Charting/Graphs
Message-Id: <3E0FFD55.6030003@thecouch.homeip.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Koos Pol wrote:
| Robert Sipe wrote (Monday 30 December 2002 05:48):
|
|
|>I need to chart performance data I extract from an SNMP daemon. Thus, I
|>will periodically poll the system for a few performance values, store
|>the data to a file, then chart it out in on a Web page. I have the SNMP
|>polling and data collection all taken care of. It is simple graph of
|>perf data vs. time. What is the recommended module/method to
|>chart/graph this data using a cgi script? Thanx in advance!
|
|
|
| http://search.cpan.org/search?query=chart
|
| That was easy, wasn't it?
|
Or there's a non-Perl solution if you don't feel like doing much coding,
however it's initial learning curve might be more than you'd like. Take
a look at RRDTool ( http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/ )
Best of luck.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+D/1VeS99pGMif6wRAgU1AJ0W3f1Gqs3lnNXgVrxJKHoOT9lnIACfc2T0
BUxhTSV875mCyHIUKNAqTPk=
=8+H8
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 30 Dec 2002 17:46:32 +0900
From: ko <kuujinbo@yahoo.com>
Subject: Check FTP links with LWP:UserAgent
Message-Id: <3E1007E8.2010600@yahoo.com>
Hi,
I'm experimenting with the LWP::UserAgent module, trying to write a link
checking routine. I would like to check FTP links also, and have come
across a problem:
use LWP::UserAgent;
my $ua = LWP::UserAgent->new(
timeout => 15,
max_size => 1,
protocols_allowed => ['http','https','ftp'],
);
my $url = 'ftp://ftp.somewhere/some_file';
my $r = $ua->get($url);
if ($r->is_success) {
print "SUCCESS ", $r->status_line(), "\n";
} else {
print "ERROR: ", $r->status_line(), "\n";
}
I get a '500 Timeout' error message even though the packet sniffer shows
a '226 Transfer complete' response from the ftp server (the URL
references a text file on a FTP server on the Internet). If 'max_size'
is commented out I get a successful response code. The problem seems to
be limited to FTP - tested a URL that points to an arbitrary file on an
HTTP server ('max_size' set to 1) and got a successful response code.
Will use the 'head' method (which works fine) when checking links. But I
have read that it may be necessary to use GET, since some servers don't
support HEAD requests. How can I check a URL using GET without
downloading the entire file? (which is what happens without setting
'max_size')
Thanks in advance,
keith
------------------------------
Date: Mon, 30 Dec 2002 10:54:00 +0200
From: "Teh (tî'pô)" <teh@mindless.com>
Subject: Re: Devel::DProf giving bad results?
Message-Id: <g9201vkno5jle0svkj21touvej1f5sdrbt@4ax.com>
Anno Siegel bravely attempted to attach 30 electrodes of knowledge
to the nipples of comp.lang.perl.misc by saying:
>According to Teh (tî'pô) <teh@mindless.com>:
>> Hi, I've just downloaded Devel::DProf from cpan.org and I'm getting
>> very suspicious results.
> Looks like Devel::DProf could use an overhaul.
>
>[test code snipped]
>
>Anno
Thanks, so I see that Devel::DProf isn't very dependable, is there
another option out there for profiling code?
------------------------------
Date: 29 Dec 2002 21:03:47 -0800
From: Ethan Brown <usenet@ethanbrown.org>
Subject: Re: Palm::Datebook generated events disappearing!
Message-Id: <m2fzsg14jw.fsf@tabrel.localdomain>
>>>>> "Ethan" == Ethan Brown <ethan@tabrel.localdomain> writes:
Ethan> I'm in the process of writing an interface between a web-based
Ethan> calendar currently out on the web (http://www.WheresTheGig.com) and my
Ethan> Palm Pilot, using the Palm::Datebook module from pilot-link.
Ethan> Everything worked fine initially. The information added by my
Ethan> application shows up correctly in JPilot. After a Palm sync it appeared
Ethan> on my Palm.
Ethan> However, after I deleted the event in the palm all subsequent event
Ethan> additions also disappear after a palm sync. So I'm seeing the following:
Ethan> (1) Run my application.
Ethan> (2) See event show up in JPilot.
Ethan> (3) Sync the palm
Ethan> (4) Event not added to palm and event gone from JPilot.
Ethan> I made sure to set the record to 'dirty', and I'm explicitly setting
Ethan> the record ID.
It seems that I can get this working if I use pilot-xfer rather than
JPilot. Here's what works:
(1) Sync the palm using the command 'pilot-xfer --sync ~/.palm'
(2) Run my application.
(3) Install the modified database using the command
pilot-xfer --install ~/.palm/DatebookDB.pdb
If I 'Sync' after running my application, the behavior occurs as
described in my original post.
Comments are welcome.
--Ethan
------------------------------
Date: 30 Dec 2002 01:24:04 -0800
From: nobull_67@yahoo.com (Brian McCauley)
Subject: Re: Parse HTTP RESPONSE Headers Active Perl CGI
Message-Id: <a8b0601f.0212300124.3d475375@posting.google.com>
Gisle Aas <gisle@ashn89ty262h.bc.hsia.telus.net> wrote in message news:<m3u1gy5aau.fsf@ashn89ty262h.bc.hsia.telus.net>...
> Brian McCauley <nobull@mail.com> writes:
> > Last I
> > knew LWP didn't implement HTTP/1.1 - specifically it didn't implement
> > "Transfer-Encoding: chunked".
>
> HTTP/1.1 and 'Transfer-Encoding: chunked' has been supported for since
> LWP-v5.60 which was released October 2001.
Gee... is it really _that_ long since I took a close look at LWP. Doesn't time fly!
------------------------------
Date: Mon, 30 Dec 2002 11:38:05 GMT
From: "Blnukem" <blnukem@hotmail.com>
Subject: Sleep Until Key Press
Message-Id: <xeWP9.194118$a8.63136@news4.srv.hcvlny.cv.net>
Hi all
Is there a way to sleep(300) or until a key is pressed say the spacebar?
Thanx
Blnukem
------------------------------
Date: 30 Dec 2002 12:13:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sleep Until Key Press
Message-Id: <aupda1$e2o$1@mamenchi.zrz.TU-Berlin.DE>
Blnukem <blnukem@hotmail.com> wrote in comp.lang.perl.misc:
> Hi all
>
> Is there a way to sleep(300) or until a key is pressed say the spacebar?
You can use alarm() to time out a read request like this:
$SIG{ ALRM} = sub { die };
alarm( 300);
my $ans;
eval { $ans = <STDIN> };
if ( defined $ans ) {
print "user replied\n";
} else {
print "timeout\n";
}
See also the faq on this: "perldoc -q 'slow event'".
Another approach could use select() to do the timeout.
Anno
------------------------------
Date: Mon, 30 Dec 2002 16:36:37 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: use perl api from csh
Message-Id: <GQVP9.9$r34.128@news.oracle.com>
I want to use the return value of
$ping->ping($host)
in my csh program
I have a perl utility module which gives me a
PingHost($Host_Name); api
Is it possible to use it from my csh file?
Thanks,
Sunil.
------------------------------
Date: 30 Dec 2002 11:56:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: use perl api from csh
Message-Id: <aupc8l$chf$1@mamenchi.zrz.TU-Berlin.DE>
Sunil <sunil_franklin@hotmail.com> wrote in comp.lang.perl.misc:
> I want to use the return value of
> $ping->ping($host)
> in my csh program
> I have a perl utility module which gives me a
> PingHost($Host_Name); api
>
> Is it possible to use it from my csh file?
Why not use the system ping if you're running csh anyway?
If you have to use Perl's ping for some reason, write a Perl script
that calls it and prints the result. Call that as `ping_script $host`
in the csh script and use the result.
Anno
------------------------------
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 4323
***************************************