Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: TIMTOWTDI Challenge: Create a filename

by grinder (Bishop)
on Jan 09, 2009 at 10:25 UTC ( #735145=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://735145]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2023-06-04 00:40 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (17 votes). Check out past polls.