in reply to Date in Filename

To get a useful short string from a date, I'd typically do something like this:
my( $sec, $min, $hour, $mday, $mon, $year ) = gmtime; my $datestamp = sprintf "%04d%02d%02d-%02d%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec;
Then you could include that in a file name, and open STDERR to it:
my $error_log = "error-$datestamp"; open STDERR, "> $error_log" or warn "Error redirecting stderr to $error_log: $!\n";
Thereafter, all writes to stderr (including from warn and die) will go to that file.

jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.

Replies are listed 'Best First'.
Re(2): Date in Filename
by chip (Curate) on May 19, 2003 at 16:08 UTC
    Why gmtime?

        -- Chip Salzenberg, Free-Floating Agent of Chaos

      There are various good reasons. One that I find compelling is that in this Internet Age, where I am and where my process runs might not be in the same timezone. Indeed, we might have many users in many timezones, and many servers in many timezones. I'm finding localtime to be rapidly diminishing in usefulness.

      jdporter
      The 6th Rule of Perl Club is -- There is no Rule #6.

      Maybe to avoid any ambiguity with DST? Otherwise, the error log could overwrite itself during the 'switching hour'.

      Cheers,Ben.