print STDOUT "Now=%Y%m%d-%H%M\n", localtime(time);
What is wrong?
How else can I print out a formatted timestamp?
Tom
Try
use POSIX qw(strftime);
print strftime "%Y%m%d-%H%M\n", localtime;
Owen
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...@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
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
...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".
[b...@morrow.me.uk]
KK> On 2008-05-04, Thomas Blabb <t.b...@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 ------ u...@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 ---------
Was I ranting? I thought I was just being complete. Thanks for the
pointer to POSIX::strftime; I seldom use the POSIX:: modules.
The attempt to use the string '%Y%m%d-%H%M' in a date formating context
told us that the OP was groping for strftime(). Considering that Owen
had figured it out several hours before you posted, I found it not very
fruitful to lead the OP away from that date formating method.