LWN.net Logo

Perl 5.14.0 released

Perl 5.14.0 released

Posted May 15, 2011 4:16 UTC (Sun) by mrons (subscriber, #1751)
Parent article: Perl 5.14.0 released

I think one of the most notable features, not mentioned in notable changes above, is the "Array and hash container functions accept references".

So now, instead of things like:

push @$arrayref, @stuff
keys %$hashref

You can write:

push $arrayref, @stuff
keys $hashref

This will help clean up a lot of the perl "line noise". I love perl sigils but the dereferencing required to use the common built-in functions just pushed sigils a bit too far.


(Log in to post comments)

Perl 5.14.0 released

Posted May 15, 2011 5:54 UTC (Sun) by jzbiciak (✭ supporter ✭, #5246) [Link]

Yes, I saw that, and I quite welcome the change!

Unfortunately, most of the perl I write is at work, where they stubbornly stick to perl 5.8 in too many places, which means I best not get in the habit of using it for a few years.

*grumble* *grumble*

Why yes, that IS a RHEL WS 4 machine under my desk. How did you know?

Perl 5.14.0 released

Posted May 15, 2011 18:51 UTC (Sun) by JoeBuck (subscriber, #2330) [Link]

Yes, RHEL 4 is basically the cross-vendor standard for the EDA (electronic design automation) industry, so a lot of us are stuck with it.

Perl 5.14.0 released

Posted May 15, 2011 20:47 UTC (Sun) by ejr (subscriber, #51652) [Link]

And a good number of parallel clusters outside EDA. ugh.

Perl 5.14.0 released

Posted May 15, 2011 21:06 UTC (Sun) by jzbiciak (✭ supporter ✭, #5246) [Link]

Yeah, that's the environment I'm in at work.

Fortunately, for the vast majority of scripting I have to do, I've been able to get away with having a "local" 5.12.1 build for our team and load up all the CPAN modules I want or need. Unfortunately, I can only use that environment within our site, so if I have to do something that runs cross-site, I likely have to fall back to the corporate standard 5.8 and the set of modules they've chosen to install.

Perl 5.14.0 released

Posted May 26, 2011 8:36 UTC (Thu) by Hausvib6 (guest, #70606) [Link]

I just got a feeling that in 2036, I'll find a VM deep inside a system in a corner of a massive data center still running Perl 5.8 and people running around in circle trying to migrate from 32bit time_t. Woohooo

Perl 5.14.0 released

Posted May 26, 2011 13:44 UTC (Thu) by jzbiciak (✭ supporter ✭, #5246) [Link]

Are you suggesting Perl 5.8 is the COBOL of our era? ;-)

Perl 5.14.0 released

Posted May 15, 2011 18:13 UTC (Sun) by alvieboy (subscriber, #51617) [Link]

I'm not sure I fully agree. I admit I have not follow development lately, but what happens if you do:

my $href = { 'a' => 'b' };
push $href, 'c';

and

my $aref = ['a','b'];
say join (' ',keys $aref);

Does it die just like it did, with classical dereferencing ? With same kind of 'exceptions' ?

I may be a bit picky, but I always like explicit dereferencing (meaning: everyone knows what to expect, no margin for doubts).

Alvie

Perl 5.14.0 released

Posted May 15, 2011 21:05 UTC (Sun) by rpkelly (guest, #74224) [Link]

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'.

Perl 5.14.0 released

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:

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:

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.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds