hi there, I have a question about a snippet of code i have which runs localtime() to convert the current date/time into a mysql happy format
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
printf "%4d-%02d-%02d %02d:%02d:%02d\n",$year+1900,$mon+1,$mday,$hour,$min,$sec;
If i run the above as a standalone script, i get the desired result
# ./time.pl
2009-09-01 10:22:18
However, what i want to do is incorporate it as part of another script and populate an internal variable with the result rather than sending it to standard out ...so i tried this
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
my $datetime = printf "%4d-%02d-%02d %02d:%02d:%02d\n",$year+1900,$mon+1,$mday,$hour,$min,$sec;
print "\n datetime equals $datetime\n";
# ./time.pl
2009-09-01 10:10:31
datetime equals 1
#
but as you can see, not only has it still output to result to standard out (not ideal), but it has populated the variable $datatime with the value "1"
is there something im doing drstically wrong here
any hlp would be great