in reply to nonempty false list
A hash slice in a scalar context returns the last element. @x{1, 2} equals (2, undef) and so undef is used as the boolean.
The second one constructs a new array, and therefore the array count is returned in a scalar context, 2.
%x = (1 => 2); print '@x{1, 2} in scalar equals: \'' . (scalar @x{1, 2}) . "'\n"; # Returns '' print '@{[@x{1, 2}]} in scalar equals: \'' . (scalar @{[@x{1, 2}]})) . + "'\n"; # Returns 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: nonempty false list
by Anonymous Monk on Mar 10, 2011 at 18:47 UTC | |
by kennethk (Abbot) on Mar 10, 2011 at 18:52 UTC | |
by wind (Priest) on Mar 10, 2011 at 18:59 UTC | |
by ikegami (Patriarch) on Mar 10, 2011 at 19:06 UTC |