Expanding a bit on gellyfish's answer, this is what I would do:
If the only thing you intend to do with all these variables is stick them in a string, you can achieve the same effect more simply using POSIX::strftime (as gellyfish suggested):use strict; use warnings; my ( $ss, $min, $hh, $dd, $mm, $yyyy ) = ( localtime )[ 0..5 ]; $mm += 1; $yyyy += 1900; $ss = sprintf( '%02d', $ss ); $min = sprintf( '%02d', $min ); $hh = sprintf( '%02d', $hh ); $dd = sprintf( '%02d', $dd ); $mm = sprintf( '%02d', $mm ); # or more succinctly with map: # ( $ss, $min, $hh, $dd, $mm ) = # map sprintf( '%02d', $_ ), $ss, $min, $hh, $dd, $mm; print "$ss $min $hh $dd $mm $yyyy\n"; __END__ 10 13 08 12 04 2005
use POSIX; my $time_string = strftime '%S %M %H %d %m %Y', ( localtime )[ 0..5 ]; print "$time_string\n"; __END__ 10 13 08 12 04 2005
the lowliest monk
In reply to Re: best way to write code
by tlm
in thread best way to write code
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |