Front page | perl.golf |
Postings from September 2002
Java v Perl dashing golf
Thread Next
From:
Andrew.Savige
Date:
September 17, 2002 07:09
Subject:
Java v Perl dashing golf
Message ID:
694BB7191495D51183A9005004C0B0540142F9D4@ir-exchange-srv.ir.com.au
I noticed a Java vs. Perl story on http://use.perl.org today.
http://developer.java.sun.com/developer/qow/archive/184/index.jsp
claimed that a 100-line Java program was twice as fast as the
Perl equivalent, but did not publish said Perl equivalent.
Anyway, davorg got it from the author and here it is:
#!/usr/bin/perl
@sunIPs=("192\\.9\\.","192\\.18\\.","192\\.29\\.");
@fileext=("\\.gif","\\.jpg","\\.css","\\.GIF","\\.JPG","\\.CSS");
$filename="$ARGV[0]";
open(IN,$filename) || die "cannot open $ARGV[0] for reading: $!";
open(OUT,">$filename.out") || die "cannot open $filename.out for writing:
$!";
LINE: while(<IN>) {
foreach $fileext (@fileext) {
next LINE if ($_ =~ /$fileext HTTP/);
}
foreach $sunIP (@sunIPs) {
next LINE if ($_ =~ /^$sunIP/);
}
print OUT;
}
I thought it might be interesting to golf this.
This is my best golf:
#!perl -n
/^192\.(9|18|29)\./|/(?i:gif|jpg|css) HTTP/||print
Curiously, this little golf program seems to flog the 15-line
original over the 100 meter dash too -- I would say the original
would be lucky to tortoise-crawl to the 25 meter line before the
golf program breasted the tape. Sorry, but I don't have proper
facilities to accurately do time comparisons right now.
I have not seriously tried the 100 meter dash, but this
one should be a little faster:
#!perl -n
/^192\.(?:9|18|29)\./||/(?i:gif|jpg|css) HTTP/ or print
/-\ndrew
Thread Next
-
Java v Perl dashing golf
by Andrew.Savige