From durango at linuxfiles.net Tue Oct 3 14:38:01 2000 From: durango at linuxfiles.net (Durango) Date: Thu Aug 5 00:07:15 2004 Subject: [Memphis.pm] Net::Ping spawned from earlier discussion Message-ID: <200010031938.OAA06153@linuxfiles.net> Hi all, I descided to look into Net::Ping as a replacement for what I have nmap doing in a perl script I'm hammering on. I made a little test prog: It yeilded the error message a little ways down... #!/usr/bin/perl -w use Net::Ping; my $host = "www.yahoo.com"; $p = Net::Ping->new(); print "$host is alive.\n" if $p->ping($host); $p->close(); [root@renegade /root]# ./plping.pl Use of uninitialized value at /usr/lib/perl5/5.00503/i386- linux/Socket.pm line 295. Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be 16 at /usr/lib/perl5/5.00503/i386-linux/Socket.pm line 295. With out digging into Socket.pm - why is this error happening or any ideas is what I'm looking for. My install is a Server install of RH 6.2 Raymond Tant http://linuxfiles.net -- NeoMail - Webmail that doesn't suck... as much. http://neomail.sourceforge.net ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From sheff at pobox.com Tue Oct 3 21:29:19 2000 From: sheff at pobox.com (Keith W. Sheffield) Date: Thu Aug 5 00:07:15 2004 Subject: [Memphis.pm] Net::Ping spawned from earlier discussion In-Reply-To: "Durango"'s message of "Tue, 3 Oct 2000 14:38:01 -0500" References: <200010031938.OAA06153@linuxfiles.net> Message-ID: >>>>> "Durango" == Durango writes: > #!/usr/bin/perl -w use Net::Ping; my $host = "www.yahoo.com"; > $p = Net::Ping->new(); print "$host is alive.\n" if > $p->ping($host); $p->close(); This works if you are root: $host="www.yahoo.com"; $p = Net::Ping->new('icmp'); print "$host is ", ($p->ping($host)) ? "alive\n" : "dead\n"; $p->close(); Not specifying a protocol or using 'tcp' or 'udp' all return dead. -- So let it be written. So let it be done. To kill the first born pharaoh son. I'm creeping Death. -- RTL:CD c4-7 Keith W. Sheffield sheff@pobox.com GPG fingerprint = 7219 D5CB 8B10 8602 2B81 AFC3 3D48 FA3F 4F51 93C9 ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From mikehopkins_98 at yahoo.com Tue Oct 3 22:33:35 2000 From: mikehopkins_98 at yahoo.com (Mike Hopkins) Date: Thu Aug 5 00:07:15 2004 Subject: [Memphis.pm] Flock Message-ID: <002101c02db5$00662ac0$0801a8c0@mike98> Can any one tell me what happens if I use flock( $file,2 ) for an exclusive file lock and my cgi program crashes before I can do the flock( $file, 8 ) thing. I feel linux is smart enough to tell the file should be unlocked if the script that locked it crashes. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/archives/memphis-pm/attachments/20001003/6dfd4f96/attachment.htm From sheff at pobox.com Tue Oct 3 23:11:27 2000 From: sheff at pobox.com (Keith W. Sheffield) Date: Thu Aug 5 00:07:15 2004 Subject: [Memphis.pm] Flock In-Reply-To: "Mike Hopkins"'s message of "Tue, 3 Oct 2000 22:33:35 -0500" References: <002101c02db5$00662ac0$0801a8c0@mike98> Message-ID: >>>>> "Mike" == Mike Hopkins writes: > Can any one tell me what > happens if I use flock( $file,2 ) for an exclusive file lock and my cgi > program crashes before I can do the flock( $file, 8 ) thing. I feel > linux is smart enough to tell the file should be unlocked if the script > that locked it crashes. I believe most Unix systems will free the lock when the file is closed, so it should unlock it. -- So let it be written. So let it be done. To kill the first born pharaoh son. I'm creeping Death. -- RTL:CD c4-7 Keith W. Sheffield sheff@pobox.com GPG fingerprint = 7219 D5CB 8B10 8602 2B81 AFC3 3D48 FA3F 4F51 93C9 ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From durango at linuxfiles.net Wed Oct 4 08:57:49 2000 From: durango at linuxfiles.net (Durango) Date: Thu Aug 5 00:07:15 2004 Subject: [Memphis.pm] Net::Ping spawned from earlier discussion Message-ID: <200010041357.IAA07084@box1> Thank you - I overlooked that variable.... I did not set the protocol. > > Not specifying a protocol or using 'tcp' or 'udp' all return dead. Raymond Tant http://linuxfiles.net -- NeoMail - Webmail that doesn't suck... as much. http://neomail.sourceforge.net ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From sheff at pobox.com Thu Oct 5 23:05:35 2000 From: sheff at pobox.com (Keith W. Sheffield) Date: Thu Aug 5 00:07:15 2004 Subject: [Memphis.pm] sorts In-Reply-To: sheff@pobox.com's message of "03 Oct 2000 21:29:19 -0500" Message-ID: I though of ways to compact the sort demos given tonight and I got the following scripts at the end of this post. Two questions 1. Is the reason why <=> doesn't work with listing #2 due to byte ordering or because perl assumes the output of pack is always a string and won't do integer compares? 2. I've tried using print ( map ..... <>), "\n"; and the last newline never gets printed. Why is that? (listing 1 is faster, BTW). ---- listing 1 ---- #!/usr/bin/perl { local $,="\n"; print map {$_->[0]} sort {$a->[1] <=> $b->[1]} map {chomp; [ $_, join('', map { sprintf "%03d", $_;} split(/\./)) ]; } <>; print "\n"; } ----- ----- listing 2 --- #!/usr/bin/perl { local $,="\n"; print map {$_->[0]} sort {$a->[1] cmp $b->[1]} map {chomp; [ $_, pack("C4", split(/\./)) ]; } <>; print "\n"; } ------ -- -------------------- Keith W. Sheffield sheff@pobox.com -------------------- NOW. Let my people go, land of goshen. GO. I will be with thee, bush of fire. -- RTL:CD v2 1-4 -------------- [lyrics copyright, Creeping Death Music, ASCAP] -------------- ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From csides at autozone.com Fri Oct 6 09:00:02 2000 From: csides at autozone.com (Carl Brock Sides) Date: Thu Aug 5 00:07:15 2004 Subject: [Memphis.pm] sort examples from last night Message-ID: <20001006090002.A2688@tanuki.autozone.com> Attached are the perl sort examples from my presentation last night. -- Brock Sides csides@autozone.com The original plan [for GNOME] was to aim to make a desktop as good as the Macintosh, and we should not lower our ambition by making one merely as good as Windows. -- RMS -------------- next part -------------- A non-text attachment was scrubbed... Name: randips.pl Type: application/x-perl Size: 222 bytes Desc: not available Url : http://mail.pm.org/archives/memphis-pm/attachments/20001006/0c5554aa/randips.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: orcache.pl Type: application/x-perl Size: 529 bytes Desc: not available Url : http://mail.pm.org/archives/memphis-pm/attachments/20001006/0c5554aa/orcache.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: schwartz.pl Type: application/x-perl Size: 426 bytes Desc: not available Url : http://mail.pm.org/archives/memphis-pm/attachments/20001006/0c5554aa/schwartz.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: sortips.pl Type: application/x-perl Size: 381 bytes Desc: not available Url : http://mail.pm.org/archives/memphis-pm/attachments/20001006/0c5554aa/sortips.bin From csides at autozone.com Fri Oct 6 10:58:00 2000 From: csides at autozone.com (Carl Brock Sides) Date: Thu Aug 5 00:07:15 2004 Subject: [Memphis.pm] sorts In-Reply-To: ; from sheff@pobox.com on Thu, Oct 05, 2000 at 11:05:35PM -0500 References: Message-ID: <20001006105800.B2688@tanuki.autozone.com> * Keith W. Sheffield [001005 23:22]: > I though of ways to compact the sort demos given tonight and I got the > following scripts at the end of this post. > > (listing 1 is faster, BTW). Strange, listing 2 is faster on my machine. csides@tanuki:~/sorting$ time ./keith1.pl < ips > /dev/null real 0m5.123s user 0m4.990s sys 0m0.110s csides@tanuki:~/sorting$ time ./keith2.pl < ips > /dev/null real 0m2.982s user 0m2.840s sys 0m0.120s Using Benchmark.pm shows that the single pack is a lot more efficient than the join/map/sprintf combo: csides@tanuki:~/sorting$ cat benchmark.pl #!/usr/local/perl-5.6/bin/perl -w use Benchmark; timethese(100000, { keith1 => 'join("", map {sprintf "%03d", $_;} split(/\./, "192.168.0.1"))', keith2 => 'pack("C4", split( /\./, "192.168.0.1"))' }); __END__ csides@tanuki:~/sorting$ ./benchmark.pl Benchmark: timing 100000 iterations of keith1, keith2... Useless use of join in void context at (eval 2) line 1. keith1: 20 wallclock secs (20.84 usr + 0.00 sys = 20.84 CPU) @ 4798.46/s (n=100000) Useless use of pack in void context at (eval 4) line 1. keith2: 6 wallclock secs ( 6.88 usr + 0.03 sys = 6.91 CPU) @ 14471.78/s (n=100000) > ---- listing 1 ---- > #!/usr/bin/perl > { > local $,="\n"; > print map {$_->[0]} sort {$a->[1] <=> $b->[1]} map {chomp; [ $_, > join('', map { sprintf "%03d", $_;} split(/\./)) ]; } <>; > print "\n"; > } > ----- > ----- listing 2 --- > #!/usr/bin/perl > { > local $,="\n"; > print map {$_->[0]} sort {$a->[1] cmp $b->[1]} map {chomp; [ $_, > pack("C4", split(/\./)) ]; } <>; > print "\n"; > } -- Brock Sides csides@autozone.com The original plan [for GNOME] was to aim to make a desktop as good as the Macintosh, and we should not lower our ambition by making one merely as good as Windows. -- RMS ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From sheff at pobox.com Sat Oct 7 22:34:07 2000 From: sheff at pobox.com (Keith W. Sheffield) Date: Thu Aug 5 00:07:15 2004 Subject: [Memphis.pm] sorts In-Reply-To: Carl Brock Sides's message of "Fri, 6 Oct 2000 10:58:00 -0500" References: <20001006105800.B2688@tanuki.autozone.com> Message-ID: >>>>> "Carl" == Carl Brock Sides writes: > * Keith W. Sheffield [001005 23:22]: >> I though of ways to compact the sort demos given tonight and I got the >> following scripts at the end of this post. >> >> (listing 1 is faster, BTW). > Strange, listing 2 is faster on my machine. > csides@tanuki:~/sorting$ time ./keith1.pl < ips > /dev/null > real 0m5.123s user 0m4.990s sys 0m0.110s csides@tanuki:~/sorting$ time > ./keith2.pl < ips > /dev/null > real 0m2.982s user 0m2.840s sys 0m0.120s > Using Benchmark.pm shows that the single pack is a lot more efficient > than the join/map/sprintf combo: That make a lot of sense. However, it could be due to the number of ips being sorted. I was sorting 100000 ips, so maybe the speed gain by the pack was being offset by having to do string compares instead of integer compares. -- -------------------- Keith W. Sheffield sheff@pobox.com -------------------- BLOOD. Running red and strong, down the Nile. PLAGUE. Darkness three days long, hail to fire. -- RTL:CD v2 5-8 -------------- [lyrics copyright, Creeping Death Music, ASCAP] -------------- ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From csides at autozone.com Fri Oct 20 11:23:48 2000 From: csides at autozone.com (Carl Brock Sides) Date: Thu Aug 5 00:07:15 2004 Subject: [Memphis.pm] bidirectional pipe Message-ID: <20001020112348.B429@tanuki.autozone.com> Suppose you have a program X, and you want to write (in Perl, of course), a wrapper W for this program. You want W to take standard input, modify it, and pass it to X; then W should get back standard out from X, and pass it back. If you were writing this in Bourne shell, it would be pretty straight forward. Let's say you want to replace all occurances of "foo" with "bar" in standard in before passing it on to X, and then replace each occurance of "baz" with "quux" in what comes back from X. Then your wrapper would look something like this: #!/bin/sh sed s/foo/bar/g | X | sed s/baz/quux That is, what you seem to need is a bi-directional pipe, to and from X. However, the way you'd think this would work in perl, doesn't. Let's say you want to open a bi-direction pipe to and from /bin/cat. You might try something like this: csides@tanuki:/tmp$ cat foo.pl #!/usr/local/perl-5.6/bin/perl -w open(CAT, "| /bin/cat |") or die $!; close CAT; __END__ However, when you try to run it: csides@tanuki:/tmp$ ./foo.pl Can't open bidirectional pipe at ./foo.pl line 3. Since the obvious answer doesn't work, what's the most elegant way to do this in perl? -- Brock Sides csides@autozone.com The original plan [for GNOME] was to aim to make a desktop as good as the Macintosh, and we should not lower our ambition by making one merely as good as Windows. -- RMS ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From csides at autozone.com Mon Oct 23 14:10:15 2000 From: csides at autozone.com (Carl Brock Sides) Date: Thu Aug 5 00:07:15 2004 Subject: [Memphis.pm] bidirectional pipe In-Reply-To: <20001020112348.B429@tanuki.autozone.com>; from csides@autozone.com on Fri, Oct 20, 2000 at 11:23:48AM -0500 References: <20001020112348.B429@tanuki.autozone.com> Message-ID: <20001023141015.B32439@tanuki.autozone.com> * Carl Brock Sides [001020 11:53]: Answering my own question. > Suppose you have a program X, and you want to write (in Perl, of > course), a wrapper W for this program. You want W to take standard > input, modify it, and pass it to X; then W should get back standard out > from X, and pass it back. [snip] > Since the obvious answer doesn't work, what's the most elegant way to do > this in perl? Perusing the IPC documentation (perldoc perlipc), I discovered IPC::Open2, which lets you open bidirectional pipes. For example, here's a generic wrapper to do gzip-encoding for a cgi script: #!/usr/local/perl-5.6/bin/perl -w -T use IPC::Open2; # the cgi we're wrapping my $cgi = '/home/csides/public_html/hello.cgi'; $ENV{'PATH'} = ''; # keep taint-checking happy if we're on the command line $ENV{'BASHRC'} = ''; # ditto open2(*READER, *WRITER, $cgi); # pass STDIN on to $cgi print WRITER ; # read in the headers from the wrapped program, # printing them to stdout. Add a Content-encoding: gzip # header unless the content is already encoded while () { $encoded = 1 if /^Content-encoding:/i; if (/^$/) { print "Content-encoding: gzip\n" unless $encoded; print; last; } } # print out the body of the response, gzipped if needed. if ($encoded) { print ; } else { open(GZIP, "| /bin/gzip -cf") or die $!; print GZIP ; } exit 0; __END__ -- Brock Sides csides@autozone.com The original plan [for GNOME] was to aim to make a desktop as good as the Macintosh, and we should not lower our ambition by making one merely as good as Windows. -- RMS ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ----------------------------------------------------------------------------