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
  • 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