Not logged in
Log in now
Create an account
Subscribe to LWN
LWN.net Weekly Edition for May 23, 2013
An "enum" for Python 3
An unexpected perf feature
LWN.net Weekly Edition for May 16, 2013
A look at the PyPy 2.0 release
Perl 5.14.0 released
Posted May 15, 2011 21:17 UTC (Sun) by jzbiciak (✭ supporter ✭, #5246)
Interesting... I didn't realize 'keys' was now valid on an array. I was a little confused by the output you gave for the second example until I realized what was happening. This appears to be a 5.12 feature I missed. I tried the following on perl 5.10 and 5.12:
my @array = qw(fred barney);
print join(" ", keys @array), "\n";
Perl 5.10 gives what I would expect:
Type of arg 1 to keys must be hash (not private array) at keys.pl line 5, near "@array)"
Execution of keys.pl aborted due to compilation errors.
In contrast, Perl 5.12 gives:
Yet another feature I didn't know about, but now I can't wait to use, but have to wait to use until 5.8 truly dies at work.
It certainly ought to make it easier to traverse arbitrary nested structures, since you wouldn't have to know whether a given element contains an array or hash reference. For example, you could start developing your structures with arrays, and switch to hashes later if you discover you benefit from sparse or non-numeric keys, and not have to change a lot of code.
Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds