Rick wrote:
below is working code but is there way to shorten this code in more perlish way?

my($DAY, $MONTH , $YEAR ) = (localtime)[3,4,5];

my $day   = sprintf("%02d",$DAY);
my $month = sprintf("%02d", ($MONTH + '1'));
my $year  = sprintf("%04d", ($YEAR + '1900'));

Why are you using a string for mathematical addition?


my $current_dir = join('', $year, $month, $day);


my ( $day, $month, $year ) = ( localtime )[ 3 .. 5 ];

my $current_dir = sprintf '%04d%02d%02d', $year + 1900, $month + 1, $day;


Or:

use POSIX 'strftime';

my $current_dir = strftime '%Y%m%d', localtime;




John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to