in reply to Re: Preventing unintended list expansion inside hash literals.
in thread Preventing unintended list expansion inside hash literals.
Interesting. I certainly agree with
a simple ($key) = %$hash_ref would have done the trick better
for clarity, terseness and, more important, lack of side effects. Unless a hash is huge:
>perl -E "$h{$_} = $_ for 0 .. 5_000_000; say time - $^T; keys %h; say + time - $^T; $k = scalar each %h; say time - $^T; say $k" 10 10 10 852569 >perl -E "$h{$_} = $_ for 0 .. 5_000_000; say time - $^T; ($k) = %h; s +ay time - $^T; say $k" 10 176 4034296
with equally bad effects on memory. Looks like keys in void context is harmless (performance-wise), but assignment of a hash to single-element list is not
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Preventing unintended list expansion inside hash literals.
by LanX (Saint) on Jan 07, 2017 at 13:38 UTC | |
|
Re^3: Preventing unintended list expansion inside hash literals.
by LanX (Saint) on Jan 06, 2017 at 20:04 UTC |