Perl treats things differently depending on context. In scalar context, localtime
returns a string representing the current (local) time. In list context, it returns a list of the various fields that make up a time value.
This problem arises because of the syntax of print
.
* print FILEHANDLE LIST
* print LIST
* print
Since print
expects a list, this puts localtime
in list context, so it returns a list of digits representing the seconds, minutes, hours, and so on, which are then concatenated by the print
function. When assigning to a scalar, localtime
is in scalar context and returns the string. If you want the concatenation of those digits, you can do something like
my $foo = join '', localtime;
print $foo;
However, perhaps a proper epoch time value would be more useful for whatever you're doing. In that case you can use time
instead.