in reply to [Updated] (localtime) versus localtime - round 1

localtime[0..2] means localtime([0..2])

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
    parenthesis are

    Should be either parenthesis is or parentheses are.

    You have nine pairs of parentheses in your example.   Which ones are you using to remove the ambiguity?

      ah thanks. And none. I was explaining why the OP's second snippet worked.

        Maybe I'm being obtuse, but I don't see the ambiguity.   :-(