Hi, I create monthly log files with names like statistics_01_2005.log. Now I have a function which returns the logfile name for the current month:
sub statfile { my @date = localtime(time); my ($month, $year) = @date[4,5]; $year += 1900; $month = sprintf ("%02d", $month+1); return my $statfile = qq{statistics_${month}_${year}.log}; } In some cases I need the name of last month's logfile. To achieve this, I modified the subroutine like this: sub statfile { my $mode = shift; my @date = localtime(time); my ($month, $year) = @date[4,5]; $year += 1900; if ($mode) { $month = sprintf ("%02d", $month); $month = 12 if $month == 0; $year = $year - 1; } else { $month = sprintf ("%02d", $month+1); } return my $statfile = qq{statistics_${month}_${year}.log}; } This looks quite clumsy to me. Is there a more elegant way? Thanks, Jan -- How many Microsoft engineers does it take to screw in a lightbulb? None. They just redefine "dark" as the new standard. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>