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 © 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |