Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re (tilly) 1: create file with current date for name

by tilly (Archbishop)
on Aug 07, 2001 at 22:31 UTC ( #102870=note: print w/replies, xml ) Need Help??

in reply to create file with current date for name

A random note. Barring specific functions to do it for you, I like constructing yyyymmdd format through a numerical operation, not a sprintf.
# Takes the time in seconds as an optional argument. # Returns the local date in yyyymmdd format. sub local_yyyymmdd { my $time = shift || time(); my ($year, $month, $mday) = (localtime($time))[5,4,3]; return 10_000*($year + 1900) + 100*($month + 1) + $mday; }
Why? Because I have met many languages without a sprintf, but none without arithmetic. And sure, it may be ugly, but that is why Larry gave us functions...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2016-10-27 10:20 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (358 votes). Check out past polls.