On 28/01/2014 07:32, Luca Ferrari wrote:
Hi all,
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.

Hi Luca

It is probably best to use the Time::Piece module, which has been part of core Perl 5 since version 10 so you shouldn't need to install it.

The program below shows how you would use it.

HTH,

Rob



use strict;
use warnings;

use Time::Piece;

my $date = localtime->strftime('%m / %d / %Y');

print "\nToday is $date\n";

**output**

Today is 01 / 29 / 2014

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


--
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