Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Answer: How do I incorporate a timestamp into a file name?

by bikeNomad (Priest)
on Jul 02, 2001 at 22:20 UTC ( #93266=categorized answer: print w/replies, xml ) Need Help??

Q&A > dates and times > How do I incorporate a timestamp into a file name? - Answer contributed by bikeNomad

The easiest way to do it (assuming you don't need to have humans interpret it) is to just use the numeric return value from time():

my $filename = $directory . '/' . time() . '.ext';
Otherwise, you can put together the various numbers from localtime:

my @lt = localtime(time); my $filename = sprintf "%s/%04d%02d%02d%02d%02d%02d", $directory, $lt[ +5]+1900, $lt[4]+1, @lt[3,2,1,0];

Log In?

What's my password?
Create A New User
Discipulus can red from white wine just even smelling it, blindfolded
Discipulus can tell..
[holli]: I'd like to put that to the test under lab conditions

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-09-25 13:30 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (280 votes). Check out past polls.