M. Lewis wrote: > > Given the following code, if I were to want $day, $month, $hour, $minute > & $sec to have a leading zero (ie 01 for Jan rather than 1), is my only > option to use printf? Or is there a better way. > > What I'm searching for here is the *correct* method to get $day, $month, > etc for uses like naming backup files (databackup-2007-01-21.tar.gz). > > > #!/usr/bin/perl > > use strict; > use warnings; > > my($sec, $min, $hour, $day, $month, $year)=(localtime)[0 .. 5]; > > print "day=$day\n"; > print "month=".($month+1)."\n"; > print "year=".($year+1900)."\n\n"; > print "hour=$hour\n"; > print "minute=$min\n"; > print "second=$sec\n\n";
use POSIX 'strftime'; print strftime "day=%d\nmonth=%m\nyear=%Y\n\nhour=%H\nminute=%M\nsecond=%S\n\n", localtime; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/