in reply to output format changed perl5.8 --> perl 5.10?
Note that I have Perl 5.8 at work, it worked, and I just tried it here at home on 5.14 and it works similarly.my @tm=localtime(time); $tm[5] += 1900; $tm[4] ++; my $timestamp = sprintf "%04d%02d%02d%02d%02d%02d", reverse @tm[0..5]; print $timestamp, "\n"; # prints something like 20140425192252
Update: BTW, just for fun, even this works correctly:
Even though I know it and have known it for quite a bit of time, I am still sometimes amazed by how easy (and fun) it is to write creative Perl code, or improbable code that still works correctly. I have used several dozens programming languages in my life, some of which I really liked, but it is different with Perl: I am really in love with it.my $timestamp = sprintf "%04d" . "%02d" x 5, @tm[ reverse 0..5];
|
|---|