Steve Haslam (araqnid) wrote,
Steve Haslam
araqnid

  • Mood:
  • Music:

NB I'm ranting

Do not structure your Perl like this (all comments are mine):

# Initialise a bunch of variables to contain the TEXT of some regexps we'll use
my $RLENGTH = '^.{627}\n$';
my $CONTENT = '^.{80}.{546}\r\n$';
# etc...

# some time later...

sub readLine {
   my ($self, $context, $line) = @_;
   $_ = $line; # why? just to make the following line prettier...
   /$RLENGTH/o ? /$CONTENT/o ? /$TREATMT/o ? /$FSTRING/o ? /$CAMPID/o ? /$EPIFANY/o ? 
   do {
      # stuff that needs to be done for this line...
   }
   # various lines like the two below...
    : print STDERR "Error Line: ", $context->getRecordNumber(), ". Invalid characters found in Email.\n"
   : print STDERR "Error Line: ", $context->getRecordNumber(), ". Bad record length.\n";
}

What a pile of dross. How many errors are there here? Admire the genius of putting the definitions of the regexps used nowhere near the code that uses them, and of having the error messages listed in the opposite order to the regexps.

What was wrong with:

sub readLine {
  my($self,$context,$line) = @_;

  eval {
    die "Bad record length\n" unless (length($line) == 628);
    die "Invalid characters found in email address\n" unless (/.{80}.{546}\r\n/);
        # this regexp is still brain-dead, though
    # stuff that needs to be done for this line...
  };
  if ($@) {
     die "Error line: ".$context->getRecordNumber().": $@\n";
  }
}

Yes, inexperience plays a part. But to get something so grotesquely fucked-up takes effort.

Subscribe

  • Reading Half-Marathon 2009

    Reading Half-Marathon 2009 Total 02:03:39 Position = 7626 out of ~17,000? The day didn't get off to too good a start: 6am on…

  • Getting back into training

    I guess it won't come as a surprise to those who know me that I've resolved to try and get fitter during the coming year. Which I've pretty much…

  • everyone's having a go...

    I see Mesh have a "God Rest Ye Merry Gentlemen" ditty on their Myspace page... Heading up to the parental home soon. Disorganised, as is…

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 3 comments