« Sur le Continent | Main | Horses of Brugge »

June 14, 2007

Bathtub example

I wrote a few days ago about the bathtub effect. Shorten code and it becomes easier to read. Shorten it too much and it becomes silly. Here's a Perl script that I wrote to report on all lines in a log file from host computer "seal" with a status code (next to last field) over 399:

open (FH,"../access_log.xyz") or die;
while ($line = <FH>) {
   if ($line =~ /^seal\s/) {
      @parts = split(/\s+/,$line);
      if ($parts[-2] > 399) {
         print $line;
      }
   }
}

And here is a shortened application which - if you look at it byte by byte - can do the same thing!

#!/usr/bin/perl -pa
(/^seal\s/&&$F[-2]>399)or$_=""

My point? Something IN BETWEEN would be, by far, best for the typical Perl programmer to understand and maintain.

Posted by gje at June 14, 2007 06:26 AM

Comments

Well House Consultants Ltd. Copyright 2010