in reply to late binding behavior in hash definition
The list of
Is identical to(1 => 2, 3 => $x{1} )
as long as %x didn't have a previous value.(1, 2, 3, undef)
In fact, it's the prior value of $x{1} that you see, as evidenced by:
%x{1} = "old x sub 1"; %x = ( 1 => 2, 3 => $x{1} );
The question for me is, why did you find this surprising or baffling? It's extremely consistent with what Perl does at all times: evaluate the right side of the assignment before altering any structure on the left. It's what permits
or@a = (2, @a)
to work.@a = reverse sort @a;
-- Randal L. Schwartz, Perl hacker
|
|---|