http://qs321.pair.com?node_id=735145


in reply to TIMTOWTDI Challenge: Create a filename

I tend to go with a variant of thezip's method, but I flow the results of the localtime slice through a coderef to make the month and years readable to an ordinary human. So it goes something like this:

my $fn = sub { sprintf "$base_name-%04d-%02d-%02d-%02d%02d%02d.ext", $_[5] + 1900, $_[4]+1, reverse(@_[0..3]) }->(localtime);

Like thezip, I use a YYYY-MM-DD format so that files sort nicely in a directory.

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^2: TIMTOWTDI Challenge: Create a filename
by dwhite20899 (Friar) on Jan 09, 2009 at 14:03 UTC
    grinder has the right idea, keeping in human readable in sort order, that's what I do, but I also toss in $$ (process id) because I have many processes making temp files, and do have collisions.