I started using this perl script on my corporate server recently and I noticed a bug in the code.
At the bottom of the script, the code reads as follows:
#short date
#add leading zero to month, if required
#first make it non-zero based
$mon++;
if ($mon<10) {
$month = “0$mon”;
}
my $shortDate = “$year-$month-$day”;[/i]
It needs to be modified in one of several ways (I have tested multiple which work, though I’‘ll leave it up to each person to execute it in their own way as I have zero perl experience and I know there is a much much more elegant solution, but I simply don’'t know enough about the language syntax to code it myself.)
The problem is this: if the value variable “mon” is 10 or greater, the variable “month” (which is used to create “shortDate”) has a value of null. This causes the resulting filename of the log file to be “2005–04.log” instead of “2005-10-04.log”
The fixes I have tried:
1)[/b] Add an else statement to the if statement that sets “month” to “mon”
#short date
#add leading zero to month, if required
#first make it non-zero based
$mon++;
if ($mon<10) {
$month = “0$mon”;
}
else {
$month = “$mon”;
}[/b]
my $shortDate = “$year-$month-$day”;[/i]
2)[/b] Modify the line assigning a value to “shortDate” to use “mon” instead of “month” and modify the if statement to assign the resulting value back to “mon”
#short date
#add leading zero to month, if required
#first make it non-zero based
$mon++;
if ($mon<10) {
$mon = “0$mon”;[/b]
}
my $shortDate = “$year-$mon-$day”;[/b][/i]
Hope this helps others that are using this perl script who may or may not have noticed this bug.
Peace,
-Bartman007