Steve Haslam (araqnid) wrote,
Steve Haslam

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


  • eep

    Almost a grand's worth of repairs needed to get the car through MOT! And even then it would appear to have an oil leak we haven't tracked down yet...…

  • repairs

    The car's in the garage (brake lights, pbsl, floor). The bike is going in next week (getting an XT chainset with hollow BB). This morning a couple of…

  • back to grindstone

    Paris was fun. I had lots of omelettes and now have blisters. Leisure Select on the Eurostar is pretty neat. Montmatre is steep. The Louvre is big.…

  • Post a new comment


    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.