|
Prev: Will Perl 6 be usable as a procedure language?
Next: FAQ 4.18 Does Perl have a Year 2000 problem? Is Perl Y2K compliant?
From: Keith Keller on 4 May 2008 14:06 On 2008-05-04, Thomas Blabb <t.blabb(a)gmail.com> wrote: > I want to print the current time(stamp) in formatted style. > The following does not work: > > print STDOUT "Now=%Y%m%d-%H%M\n", localtime(time); Did you read perldoc -f localtime? If you are happy with localtime's formatting, simply print it as a scalar: print scalar localtime(); If you want to use a print-equivalent statement to do your formatting, you need to use printf. Also, perl date formatting has nothing to do with UNIX date; %Y for example is the hash named Y, and bears no relation at all to your call to localtime. Read perldoc -f sprintf for valid formats (%Y is certainly not one). --keith -- kkeller-usenet(a)wombat.san-francisco.ca.us (try just my userid to email me) AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt see X- headers for PGP signature information
From: Gunnar Hjalmarsson on 4 May 2008 14:22 Keith Keller wrote: > perl date formatting has nothing to do with UNIX date; %Y for example > is the hash named Y, and bears no relation at all to your call to > localtime. Read perldoc -f sprintf for valid formats (%Y is > certainly not one). Wouldn't it have been better to point the OP to POSIX::strftime() and drop that rant? -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
From: Ben Morrow on 4 May 2008 14:29 Quoth Keith Keller <kkeller-usenet(a)wombat.san-francisco.ca.us>: > On 2008-05-04, Thomas Blabb <t.blabb(a)gmail.com> wrote: > > I want to print the current time(stamp) in formatted style. > > The following does not work: > > > > print STDOUT "Now=%Y%m%d-%H%M\n", localtime(time); > <snip> > If you want to use a print-equivalent statement to do your formatting, > you need to use printf. Also, perl date formatting has nothing to do > with UNIX date; %Y for example is the hash named Y, and bears no > relation at all to your call to localtime. Read perldoc -f sprintf for > valid formats (%Y is certainly not one). ....however it is a valid format for strftime, which I suspect is what the OP wanted. use POSIX qw/strftime/; print STDOUT strftime "Now=%Y%m%d-%H%M\n", localtime; Ben -- I have two words that are going to make all your troubles go away. "Miniature". "Golf". [ben(a)morrow.me.uk]
From: Uri Guttman on 4 May 2008 14:38 >>>>> "KK" == Keith Keller <kkeller-usenet(a)wombat.san-francisco.ca.us> writes: KK> On 2008-05-04, Thomas Blabb <t.blabb(a)gmail.com> wrote: >> print STDOUT "Now=%Y%m%d-%H%M\n", localtime(time); KK> If you want to use a print-equivalent statement to do your formatting, KK> you need to use printf. Also, perl date formatting has nothing to do KK> with UNIX date; %Y for example is the hash named Y, and bears no KK> relation at all to your call to localtime. Read perldoc -f sprintf for KK> valid formats (%Y is certainly not one). actually %Y is just the string '%Y' there. hashes don't interpolate in strings. and yes, the OP is confusing time formats (date and strftime) with printf formats. uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Keith Keller on 4 May 2008 16:54
On 2008-05-04, Gunnar Hjalmarsson <noreply(a)gunnar.cc> wrote: > Keith Keller wrote: >> perl date formatting has nothing to do with UNIX date; %Y for example >> is the hash named Y, and bears no relation at all to your call to >> localtime. Read perldoc -f sprintf for valid formats (%Y is >> certainly not one). > > Wouldn't it have been better to point the OP to POSIX::strftime() and > drop that rant? Was I ranting? I thought I was just being complete. Thanks for the pointer to POSIX::strftime; I seldom use the POSIX:: modules. --keith -- kkeller-usenet(a)wombat.san-francisco.ca.us (try just my userid to email me) AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt see X- headers for PGP signature information |