To celebrate leveling up today, I dug through my code archives and picked one of the oldest full scripts I could find. Although I wrote my first Perl scripts in about 1995, unfortunately those appear to be lost on an old MacBook that won't boot up anymore. Maybe I'll get around to recovering it someday, but for now, here's a script with a modification date of October 1998.

I guess we all have to start somewhere ;-) Can you spot all the bad practices? What does your old Perl code look like?

#!perl # Vars $date = localtime(time); # Website Directory (absolute path, no trailing \) $webdir="F:\\Data\\MyWebsite"; print "*** AutoFooter @ $date ON $webdir\n"; # Start Log open(LOG,">C:\\autofoot.log") || die "Couldn't open logfile: $!\n"; print LOG "*** AutoFooter @ $date ON $webdir\n"; # Get Root $slashes=1; while($webdir=~/\\/g) {$slashes++;} # Get Files print "*** Getting File list...\n"; chdir($webdir); $dirl=`DIR *.html /S/B`; @files=split(/\n/,$dirl); # Foot Files print "*** Running Footer...\n"; foreach $file (@files) { print LOG "File: $file - "; open(FILE,"$file") || die "Couldn't open $file for input: $!\n"; @lines=<FILE>; close(FILE); $foot=0; foreach $_ (@lines) {$foot=1 if /AUTOFOOTER/;} if($foot) { &getpath; print LOG "Applying \"$path\"\n"; open(FILE,">$file") || die "Couldn't open $file for output: $!\n"; foreach $_ (@lines) { if(/AUTOFOOTER/) { &dofoot; last; } elsif(/^\<LINK REL\=stylesheet.+\>$/) { print FILE "<LINK REL=stylesheet TYPE=\"text/css\" HREF=\"$pat +h\style.css\">\n"; } elsif(/^\<BODY.+\>$/) { print FILE "<BODY BGCOLOR=\"#FFFFFF\">\n"; } else { print FILE $_; } } close(FILE); } else { print LOG "Skipped\n"; } } print LOG "*** Done\n"; close(LOG); print "*** Done\n"; # ----- GETPATH ----- sub getpath { $cnt=-$slashes; while($file=~/\\/g) {$cnt++;} $path = '../' x $cnt; } # ----- DOFOOT ------ sub dofoot { $f1=$path."pics/totop.gif"; $f2=$path."pics/logo.gif"; $f3=$path."email.html"; $f4=$path."search.html"; print FILE <<"(END FOOT)"; <!-- AUTOFOOTER --> <CENTER><A HREF="#Top"><IMG SRC="$f1" WIDTH="22" HEIGHT="22" ALT="^^ T +o Top ^^" BORDER=0></A></CENTER> <HR> <TABLE WIDTH="100%" BORDER=0><TR> <TD ALIGN=LEFT VALIGN=TOP> <IMG SRC="$f2" WIDTH=40 HEIGHT=20 ALT="Logo" ALIGN="MIDDLE"> <FONT FACE="Arial" SIZE="-1" ID="foottext"><I> Copyright &copy; 1998 Hauke Daempfling<BR> Last Updated <SCRIPT LANGUAGE="JavaScript"><!-- document.write(document.lastModified); // --> </SCRIPT> </I></FONT> </TD><TD ALIGN=RIGHT VALIGN=TOP> <FONT SIZE="-2" FACE="Arial" ID="lnkfont"> <NOBR>[ <A HREF="$f4" TARGET="_self" ID="ln">Site Search</A> ]</NO +BR> <NOBR>[ <A HREF="http://www.zero-g.net/cgi-bin/struct/index.cgi" T +ARGET="_self" ID="ln">Site Map</A> ]</NOBR> <NOBR>[ <A HREF="$f3" TARGET="_self" ID="ln">EMail</A> ]</NOBR> </FONT> </TD> </TR></TABLE> </BODY> </HTML> (END FOOT) }

In reply to What does your old Perl code look like? by haukex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.