in reply to Re: Date Extraction
in thread Date Extraction

When dealing with localtime and similar functions, I'd like to name the elements that it returns explicitly:
my ($sec, $min, $hour, $day, $mon, $year) = (localtime)[0..5]; my $time = sprintf "%04d" . "%02d" x 5, $year + 1900, $mon + 1, $day, $hour, $min, $sec; print $time;
And presto! Self-documenting code :-)

Arjen

Replies are listed 'Best First'.
Re: Re: Re: Date Extraction
by ysth (Canon) on Dec 18, 2003 at 08:16 UTC
    Obligatory mention of Time::Piece:
    use Time::Piece; my $t = localtime; printf "%.4d"."%.2d"x5, $t->year, $t->mon, $t->mday, $t->hour, $t->min +, $t->sec;