Main Content

Bathtub example

Archive - Originally posted on "The Horse's Mouth" - 2007-06-14 06:26:34 - Graham Ellis

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.