in reply to Date in Filename

Provided that your script name does not contain the percent sign :
use strict; use POSIX; my $filename = strftime "$0.%Y%m%d-%H%M%S.log", localtime();
strftime is a really cool function for timestamps, but documentation is scarce. The DateTime module has more/better documentation on the format strings than the stock Perl/POSIX documentation.
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

Replies are listed 'Best First'.
Re: Re: Date in Filename
by chip (Curate) on May 19, 2003 at 16:06 UTC
    Tsk, passing unchecked data ($0) to strftime ... shame! What if somebody creates a symlink to the script, and that symlink's name contains a "%"; or what if there's a "%" in the path leading to the script? Then strftime is gonna get Really Mad, that's what.

        -- Chip Salzenberg, Free-Floating Agent of Chaos