I would like to assign the output of printf to a variable in perl , it give me back a "1" instead of the time. How can I stuff the variable with what printf returns?
Here is my code:
#!/usr/bin/perl
$time = localtime(time);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$newtime = printf ("%4d-%02d-%02d %02d:%02d:%02d",$year+1900,$mon+1,$mday,$hour,$min,$sec);
print "$newtime\n";
Any suggestions?
Thanks in advance.
SFNYC
April 2, 2009, 5:01pm
2
Try
$ cat ./mycode
#!/usr/bin/perl
$time = localtime(time);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$newtime = sprintf ("%4d-%02d-%02d %02d:%02d:%02d",$year+1900,$mon+1,$mday,$hour,$min,$sec);
print "$newtime\n";
$ ./mycode
2009-04-02 16:55:311
dabheeruz:
I would like to assign the output of printf to a variable in perl , it give me back a "1" instead of the time. How can I stuff the variable with what printf returns?
Here is my code:
#!/usr/bin/perl
$time = localtime(time);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$newtime = printf ("%4d-%02d-%02d %02d:%02d:%02d",$year+1900,$mon+1,$mday,$hour,$min,$sec);
print "$newtime\n";
Any suggestions?
Thanks in advance.
You can't, you need to to use sprintf.