With the magic of perlbrew, you can install 5.14.0 locally without interfering with your system perl! That said, your first example dies with 'Not an ARRAY reference'. Your second example will print '0 1'.
Posted May 15, 2011 21:17 UTC (Sun) by jzbiciak (✭ supporter ✭, #5246)
[Link]
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:
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:
0 1
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.