Thanks for the help. Just as a side note, the check for $days being less
than one was after I put the first version in production. I had the day
value being subtracted somewhere else, so the first of the month because 0
instead of 28, 30, or 31. Which is where the subroutine came to be.
On Mon, 9 Jul 2001, Jeff 'japhy' Pinyan wrote:
> ### comments are inlined
> ### -- japhy
>
> # This sets up the values for the $date variable
> (my $sec, my $min, my $hour, my $mday, my $mon, my $year, my $wday, my
> $yday, my $isdst) = localtime(time);
>
> ### you might want to rewrite this as:
> ###
> ### my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
> ### localtime;
> ###
> ### however, I doubt you really use all those variables, so only store the
> ### ones you need:
> ###
> ### my ($mday, $mon, $year) = (localtime)[3,4,5]; # list slice
>
> # This puts us in the right directory
> chdir("d:\\glsofts\\slecmea\\log");
>
> # These lines move the respective log files to the old directory
> move ("$event.log", "d:\\glsofts\\slecmea\\log\\old\\$event-$date.log");
> move ("$send.log", "d:\\glsofts\\slecmea\\log\\old\\$send-$date.log");
> move ("$recv.log", "d:\\glsofts\\slecmea\\log\\old\\$recv-$date.log");
>
> ### windows DOES allow forward slashes to be used here -- you might want
> ### to use them to make your code less "noisy"
>
>
> # This is the subroutine that handles the last day of the month
> sub datefix {
> my ($month,$day) = @_;
> if ($day <= 1 && $month !~ /[5,7,10,12]/)
>
> ### when is $day going to be LESS than 1?
> ### character classes (the [...] in a regex) match CHARACTERS.
> ### your character class is [01257,] -- I don't think that's what you
> ### wanted; change it to
> ###
> ### if ($day == 1 and $month !~ /^(5|7|10|12)$/) { ... }
> ###
> ### but this code should be rewritten with a constant array that relates
> ### months to the days in them:
> ###
> ### @days = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
> ### $day = --$day || $days[$month - 1];
> ### # if $day was 1, --$day is 0, which means we need to calculate
> ### # the last day of the previous month
> ###
> ### that will work even if $month is 0 (January) since $days[-1] is the
> ### last element of @days. please remember to do the adjusting for
> ### $days[1] to make sure leap years are accounted for properly
>
>