chris blogs

July 2004

15jul2004 · The most awful Perl script

I’ve seen the most awful Perl script ever. I guess it’s the first Perl the author ever wrote. It’s purpose is to provide a server that returns Lotto numbers.

I don’t really want to reproduce it as a whole, but only the “greatest” lines of code.

It starts by neither using use warnings; nor use strict;. Please do that all the time.

For example:

foreach $nologing (@lottotip)
print "$nologing ";
print "\n";

Well, why easy if you can have it complicated? I guess most people would prefer:

print "@lottotip\n";

Another cool thing are the variable names, for example:


This would translate to:


The main thing is the Lotto number generation function:

sub tip
   # Unterprogramm welches Lottotip erzeugt.
   # Gibt ein Array namens "lottotip" zurück.

“It returns an array called `lottotip’”. Wow. I didn’t know Perl had named arrays. ;-) :

   # Aufruf des Unterprogrammes erfolgt mit "&tip"

“You call this subroutine by `&tip’”. I guess the casual Perl programmer knows that. The “&” is optional in modern Perl, BTW. :

   srand; # Zufallsgenerator starten

You shouldn’t srand inside a subroutine, do it once in the main program. :


     # Zufallszahl erzeugen

     # Schauen ob zwischen 0 und 46
     if($lottozufall == 0 || $lottozufall > 45)
        goto lottozufallwieder;

$lottozufall=int(rand(45)+1); would have been easier. goto, yuck! (next exists, by the way.) :

     # Schauen das keine Lottozahlen im Tip doppelt vorkommen
     while($lottoarraycheck < 6)
        if($lottozufall == $lottotip[$lottoarraycheck])
        goto lottozufallwieder;

You know goto is evil? :


    return @lottotip;
   # Subfine

That was an awful way to write:

sub tip {
  return(sort { rand() <=> rand() } (1..45))[1..6];

Some code just shouldn’t be published…
and some people can write Basic in all languages. ;-)

NP: Pearl Jam—Porch

Copyright © 2004–2016