Because the first example uses a hex representation of an integer, and the second example uses a string of characters that happen to include a 0x and some stuff that looks (to a human) hex-ish (but not to Perl). Perl converts that string to a number following Perl's numerification of a string rules, which in this case results in a '0'.
use strict; use warnings; use diagnostics; my $daTime = "0x506143ca"; print scalar localtime $daTime, "\n";
...the output...
Argument "0x506143ca" isn't numeric in localtime at mytest.pl line 10 +(#1) (W numeric) The indicated string was fed as an argument to an oper +ator that expected a numeric value instead. If you're fortunate the me +ssage will identify which operator was so unfortunate. Wed Dec 31 16:00:00 1969
As for the "Wed Dec 31 16:00:00 1969": perl -E 'say localtime 0' will yield the same result.
Dave
In reply to Re: Hex, Localtime and strings
by davido
in thread Hex, Localtime and strings
by theneil
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |