in reply to [Updated] (localtime) versus localtime - round 1
You are constructing an array with three elements, getting a reference to it and passing it to localtime. localtime treats the reference as a number, resulting in the address, and uses the address as the number of seconds since epoch.
use POSIX qw( strftime ); my $ref = [ 0 .. 2 ]; print($ref, "\n"); printf("%X\n", 0+$ref); print(strftime('%Y-%m-%d %H:%M:%S', localtime($ref)), "\n"); print(strftime('%Y-%m-%d %H:%M:%S', localtime(0+$ref)), "\n");
ARRAY(0x225248) 225248 1970-01-26 19:48:08 1970-01-26 19:48:08
The parentheses are necessary to remove the ambiguity (by requiring an operator instead of an expression).
perl -MO=Deparse and perl -MO=Deparse,-p help with parsing problems.
Update: Corrected spelling mistake pointed by jwkrahn.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: (localtime) versus localtime - round 1
by jwkrahn (Abbot) on Sep 28, 2008 at 05:35 UTC | |
by ikegami (Patriarch) on Sep 28, 2008 at 06:58 UTC | |
by jwkrahn (Abbot) on Sep 28, 2008 at 07:04 UTC | |
by ikegami (Patriarch) on Sep 28, 2008 at 07:48 UTC |