Walt Mankowski on Tue, 28 Dec 1999 23:45:17 -0500 (EST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Y2K Fun


Believe it or not, I actually found some pretty serious Y2K issues on
our website today.  After all our joking around about 19100, I decided
to audit our site for calls to localtime.  I found a whole lot of code
that was doing stuff like this:

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$date = sprintf("%02d%02d%02d", $year, $mon, $mday);

We generally do stuff like this to create dated files like logs and
whatnot.  It wouldn't have crippled our site, but it would have
prevented us from checking the logs to see if anything was else wrong.

I am embarrassed to admit that I may have written some of this code
myself.  I'm also mad at myself for not checking for this months ago.
In my defense, I was busy writing VBScript and ASP pages back then
while my PHB had our most junior, inexperienced programmer auditing
our site for Y2K issues.  I checked what he changed, but not what he
didn't change.  :-(

Fortunately, most of these problems are easily fixed by changing $year
to substr($year, -2), and I get to be a hero by finding and fixing it
at the last minute.

But one of the scripts just had be shaking my head.  It doesn't give
away any trade secrets, so I'm just going to quote the entire
subroutine as an example of just how bad Perl can get in the wrong
hands.  It's really amazing to me that the guy who wrote this has
managed to keep a steady job as a programmer for the past 5 years or
so.  It's also not immediately clear how to fix it.  The
date-timestamp he's creating is already so fscked up that I doubt it
would be much worse if it started with "100" instead of "99".

So anyway, here it is.  Enjoy.  If Schwern does another "Ineffective
Perl Programming" talk at YAPC next year, I think this would be a
prime candidate to be included.

Walt

P.S.  In case you're wondering, yes, this is the original formatting.

sub Copy
{
     $ThisDir = $_[0];
     $ThatDir = $_[1];
     (-e  "$MigrationDrive$ThisDir") || return FALSE;

     &LogThis ("renaming dlls-- directory : $ThatDir\n");
     opendir (DIR, "$MigrationDrive$ThisDir");
     while ($name=readdir(DIR))
      {
       next if ($name eq "." || $name eq "..");
       next unless ($name =~ /dll/i);
          local ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdt) = localtime (time);
          $NewName = sprintf("$name.%d%d%d%d%d.old",$year,$mon,$mday,$hour,$min);
          system "ren  $RootDrive$ThatDir\\$name $NewName";
       &LogThis ("ren $RootDrive$ThatDir\\$name $RootDrive$ThatDir\\$NewName");

      }
     &LogThis ("Copying From Migration-- directory : $ThisDir\n");
     print "Copying From Migration-- directory : $ThisDir<BR>\n";
     system ("mkdir $RootDrive$ThatDir") unless (-d "$RootDrive$ThatDir");
     &LogThis ( "xcopy /i /v R $MigrationDrive$ThisDir\\*.* $RootDrive$ThatDir\n");
     system "xcopy /i /v /R $MigrationDrive$ThisDir\\*.* $RootDrive$ThatDir";

      $ErrorCode = $!;
      system "dir /s $MigDrive$MigDir$Migration" if ($returned != 0);
     &KeelOver ("$ErrorCode : Bad Medium or other error. (copy)") if ($returned != 0);

}
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**