FAQ

On 2014-01-28 08:32, Luca Ferrari wrote:

often I find myself writing something like the following to get the
"human" date:

my ($day, $month, $year) = (localtime())[3..5];
$month++, $year += 1900;
print "\nToday is $month / $day / $year \n";


I was wondering if there's a smarter pattern to get the right value in
one single line. At least there's no simple "map" I can think of.
perl -wE'
    say sprintf "%s-%02d-%02d",
                map {$_->[5]+1900, $_->[4]+1, $_->[3]}
                    [localtime];
'
2014-01-28


perl -MPOSIX=strftime -wE'
    say strftime "%F", localtime;
'
2014-01-28


perl -MTime::Piece -wE'
    say localtime->strftime("%F");
'
2014-01-28

--
Ruud

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 9 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedJan 28, '14 at 7:32a
activeJan 29, '14 at 2:28p
posts9
users8
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase