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
In reply to Re^2: Preventing unintended list expansion inside hash literals.
by vr
in thread Preventing unintended list expansion inside hash literals.
by gregory-nisbet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |