or...why I've reaffirmed my decision to hide in my basement come New
Years Eve.
Scenario:
A consultant at a company who has 16 divisions on one web server and most
of them using Matt Wright scripts, whose web masters haven't given a
thought to checking their sites for Y2K problems/compliance is asked to
help resolve these issues....in the latter part of December.
Unusual or uncommon problem? I highly doubt it.
Script:
Matt Wright's infamous little FormMail.pl which features the dreaded
19$year.
The following date routine works, but this is the newer version..
sub get_date {
# Define arrays for the day of the week and month of the year.
# #
@days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');
# Get the current time and format the hour, minutes and seconds. Add
# #
# 1900 to the year to get the full 4 digit year.
# #
($sec,$min,$hour,$mday,$mon,$year,$wday) =
(localtime(time))[0,1,2,3,4,5,6];
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$year += 1900;
# Format the date.
# #
$date = "$days[$wday], $months[$mon] $mday, $year at $time";
}
Older version [ which every site I dealt with today contained ]
sub get_date {
@days =
('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }
$date = "$days[$wday], $months[$mon] $mday, 19$year at
$hour\:$min\:$sec";
}
Now, regardless of whether or not the first one works, both seem to be a
heck of a lot of work, WAY too much work for a simple $date. Why does he
go to all this trouble? I'm not sure I can answer that. I checked and
rechecked why he might be going through all of this work just to get a
formatted date, e.g. I thought maybe he used the variables elsewhere for
soemthing else...but, nope, he only uses $date and nothing more. And,
well, sure, he is formatting a 'pretty' date, but since it serves no
critical function to the application itself, why work so hard?
Solution:
sub get_date {
$date = scalar localtime;
}
yes, that's it. Now, I realise that this isn't portable to NT nor does it
address the myriads of other problems with this script which I plan to
replace in the near future, but one must choose their battles wisely. This
is a quick, simple, transparent [ to the webmasters, 'developers' and
users alike ] change that will keep running smoothly until a sooner rather
than later time.
I have avoided looking at most of Matt Wrights stuff, but I think even a
student learning Perl could write more saavy stuff than this. It also
reaffirms my thought that there really should be more scripts available on
CPAN so that people don't have to use crap like this if they are too lazy
to write something themselves...
Ok, someone be enthused and go for it! :)
I'd also love to see a treatise/article on the joys of Date and Time with
Perl but I already got my wish for Christmas and New Years for the next
Millenia so someone else will need to ask :)
e.