Perl Timestamp two-liner

I was surprised that Perl does not have a convenient oneliner to get a timestamp fast enough, such as Ruby has. Nonetheless I did not give up and researched a bit to come up with the following:

my @now = localtime;
 sprintf("%d%02d%02d",$now[5]+1900,$now[4]+1,$now[3]);

This outputs something like “20091006”.

Though this is a two-liner, it is best I have found this far.

2 thoughts on “Perl Timestamp two-liner

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s