Re: baby perl to get the right date
On Jan 27, 2014, at 11:32 PM, Luca Ferrari fluca1...@infinito.it 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. The localtime() function in scalar context returns a string containing the date and time. See ‘perldoc -f localtime’ for details. For example, here’s what I put at the beginning of my program to print out the date and time the run started: print “Run started at “, scalar localtime(), “\n”; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: baby perl to get the right date
On Jan 28, 2014, at 8:59 PM, Rob Dixon wrote: It is probably best to use the Time::Piece module, which has been part of core Perl 5 since version 10 Side question: does anyone know why the Perl team chose Time::Piece over Date::Time to be bundled with Perl? I've known about Date::Time for awhile now, but this is the first I've heard of Time::Piece. Just curious. Frank http://www.surfshopcart.com/ Setting up shop has never been easier!
Re: baby perl to get the right date
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 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: baby perl to get the right date
On Tue, 28 Jan 2014 08:32:20 +0100 Luca Ferrari fluca1...@infinito.it 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. I tend to use DateTime to manipulate dates, so I'd say something like DateTime-now-dmy('/'); It's a bit of a slow and heavyweight way to go about it if you're not already planning to use DateTime, though :) -- David Precious (bigpresh) dav...@preshweb.co.uk http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook www.preshweb.co.uk/cpanwww.preshweb.co.uk/github -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: baby perl to get the right date
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/
Re: baby perl to get the right date
On Wed, Jan 29, 2014 at 5:59 AM, Rob Dixon rob.di...@gmx.com wrote: 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. Thanks, I was not aware of it. And it does what I need. Luca -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
baby perl to get the right date
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. Thanks, Luca -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: baby perl to get the right date
Hi Luca, Check this: http://stackoverflow.com/questions/11020812/todays-date-in-perl-in-mm-dd--format On 28 January 2014 13:02, Luca Ferrari fluca1...@infinito.it 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. Thanks, Luca -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- Regards, Chankey Pathak http://www.technostall.com/
Re: baby perl to get the right date
hi If you would like to work with a cleaner perl, try: http://search.cpan.org/~mschwern/perl5i-v2.12.0/lib/perl5i.pm it is slower but it is beautiful. other way is to use Classes like DateTime directly Best Regards MArcos On Tue, Jan 28, 2014 at 8:32 AM, Luca Ferrari fluca1...@infinito.it 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. Thanks, Luca -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- Marcos Rebelo http://www.oleber.com/ Webmaster of http://perl5notebook.oleber.com