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

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2022-05-18 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (71 votes). Check out past polls.

    Notices?