Perl can do that now!

Last week saw the releaseof Perl 5.34.0 (you can get it here), and with it comes a year’s worth of new fea­tures, per­for­mance enhance­ments, bug fix­es, and oth­er improve­ments. It seems like a good time to high­light some of my favorite changesover the past decade and a half, espe­cial­ly for those with more dat­ed knowl­edge of Perl. You can always click on the head­ers below for the full releas­es’ perldeltapages.

Perl 5.10(2007)

This was a big release, com­ing as it did over five years after the pre­vi­ous major 5.8 release. Not that Perl devel­op­ers were idle—but it would­n’t be until ver­sion 5.14 that the lan­guage would adopt a steady year­ly release cadence.

Due to the build-​up time, many core enhance­mentswere made but the most impor­tant was arguably the featureprag­ma, enabling the addi­tion of new syn­taxthat would oth­er­wise break Perl’s back­ward com­pat­i­bil­i­ty. 5.10 also intro­duced the defined-​or oper­a­tor(//), statevari­ablesthat per­sist their pre­vi­ous val­ue, the sayfunc­tionfor auto­mat­i­cal­ly append­ing a new­line on out­put (so much saved typ­ing), and a large col­lec­tion of improve­ments to reg­u­lar expres­sions. In addi­tion, this release intro­duced smart match­ing(~~), though ver­sion 5.18 would even­tu­al­ly rel­e­gate it to exper­i­men­tal sta­tus.

Perl 5.12(2010)

This release also saw many new fea­turesadded, but if I had to pick one mar­quee item it would be exper­i­men­tal sup­port for plug­gable key­words, which enabled authorsto extend the lan­guage itselfwith­out mod­i­fy­ing the core. Previously one would either use plain func­tions, hacky source fil­ters, or the dep­re­cat­ed Devel::Declaremod­ule to sim­u­late this func­tion­al­i­ty. CPAN authors would go on to cre­ate all kinds of new syn­tax, some­times pro­to­typ­ing fea­tures that would even­tu­al­ly make their way into core.

Perl 5.14(2011)

5.14 had a big list of enhance­ments, includ­ing Unicode 6.0 sup­portand a gag­gle of reg­u­lar expres­sion fea­tures. My favorite of these was the /rswitch for non-​destructive sub­sti­tu­tions.

But as the first year­ly cadence release, the changes in pol­i­cytook cen­ter stage. The Perl 5 Porters (p5p) explic­it­ly com­mit­tedto sup­port­ing the two most recent sta­ble release series, pro­vid­ing secu­ri­ty patch­es only for release series occur­ring in the past three years. They also defined an explic­it com­pat­i­bil­i­ty and dep­re­ca­tion pol­i­cy, with def­i­n­i­tions for fea­tures that may be exper­i­men­tal, dep­re­cat­ed, dis­cour­aged, and removed.

Perl 5.16(2012)

Another year, anoth­er ver­sion bump. This time the core enhance­mentswere all over the map (although no enhance­ments to the mapfunction 😀 ).

May I high­light anoth­er doc­u­men­ta­tion change, though? The perlootut Object-​Oriented Programming in Perl Tutorial replacedthe old perltoot, perltooc, perlboot, and perlbotpages, pro­vid­ing an intro­duc­tion to object-​oriented design con­cepts before strong­ly rec­om­mend­ingthe use of one of the OO sys­tems from CPAN. Mentioned are Moose, its alter­na­tive Mouse, Class::Accessor, Object::Tiny, and Role::Tiny​’s usage with the lat­ter two. Later ver­sions of perlootutwould rec­om­mend Moorather than Mouse.

Perl 5.18(2013)

As men­tioned ear­li­er, Perl 5.18 ren­dered smart­match exper­i­men­tal, as well as lex­i­cal useof the $_vari­able. With these came a new cat­e­go­ry of warn­ingsfor exper­i­men­tal fea­tures and a method for over­rid­ing such warn­ingsfeature-​by-​feature. Fitting in with the secu­ri­tyand safe­ty theme, hash­es were over­hauledto ran­dom­izekey/​value order, increas­ing their resis­tance to algo­rith­mic com­plex­i­ty attacks.

But it was­n’t all fenc­ing in bad behav­ior. Lexical sub­rou­tinesmade their first (exper­i­men­tal) appear­ance, and although I con­fess I haven’t had much call for them in my work, oth­ers have come up with some inter­est­ing uses. Four years lat­er they became non-​experimental.

Perl 5.20(2014)

Three new syn­tax fea­tures arrived in 2014: exper­i­men­tal sub­rou­tine sig­na­tures(of which I’ve writ­ten more about here), key/​value hash slices and index/​value array slices, and exper­i­men­tal post­fix deref­er­enc­ing. This last enables clean­er left-​to-​right syn­taxwhen deref­er­enc­ing variables:

  • @{ $array_ref }becomes $array_ref->@*
  • %{ $hash_ref }becomes $hash_ref->%*
  • Etc.

Postfix deref­er­enc­ing became non-​experimental in Perl 5.24, and vig­or­ous dis­cus­sion con­tin­ueson sub­rou­tine sig­na­tures’ future.

Perl 5.22(2015)

Speaking of sub­rou­tine sig­na­tures, their loca­tion movedto between the sub­rou­tine name (if any) and the attribute list (if any). Previously they appeared after attrib­ut­es. The les­son? Remain con­scious of exper­i­men­tal fea­tures in your code, and be pre­pared to make changes when upgrading.

In addi­tion to the enhance­ments, secu­ri­ty updates, per­for­mance fix­es, and dep­re­ca­tions, devel­op­ers removed the his­tor­i­cal­ly notable CGI mod­ule. First added to corein 1997 in recog­ni­tion of its crit­i­cal role in enabling web devel­op­ment, it’s been sup­plant­ed by bet­ter alter­na­tiveson CPAN.

Perl 5.24(2016)

Perl 5.20​’s post­fix deref­er­enc­ing was no longer exper­i­men­tal, and devel­op­ers removed both lex­i­cal $_and autoderef­er­enc­ingon calls to push, pop, shift, unshift, splice, keys, values, and each.

Perl 5.26(2017)

The incor­po­ra­tion of exper­i­men­tal fea­tures con­tin­ued, with lex­i­cal sub­rou­tines mov­ing into full sup­port. I like the added read­abil­i­ty enhance­ments, though: indent­ed here-​documents; the /xxreg­u­lar expres­sion mod­i­fi­erfor tabs and spaces in char­ac­ter class­es; and @{^CAPTURE}, %{^CAPTURE}, and %{^CAPTURE_ALL}for reg­exp match­es with a lit­tle more self-documentation.

Perl 5.28(2018)

Experimental sub­rou­tine sig­na­ture and attribute order­ing flipped backto its Perl 5.20 sequence of attributes-​then-​signature. Bit of a roller­coast­er ride on this one. You could do worse than using some­thing like Type::Paramsuntil this set­tles and get a wide vari­ety of type con­straints in the bargain.

Perl 5.30(2019)

Pour one out for AWK and Fortran pro­gram­mers migrat­ing to Perl: the $[vari­ablefor set­ting the low­er bound of arrays could no longer be set to any­thing oth­er than zero. This had a long dep­re­ca­tion cycle start­ing in Perl 5.12.

Perl 5.32(2020)

In 2020 Perl’s devel­op­ment moved to GitHub. And once again, I’m going to high­light read­abil­i­ty enhance­ments: the exper­i­men­tal isaoper­a­torcould be used to say:

if ( $obj isa Some::Class ) { ... }

instead of

use Scalar::Util 'blessed';
if ( blessed($obj) and $obj->isa('Some::Class') { ... }

You could also chain com­par­i­son oper­a­tors, lead­ing to the more math­e­mat­i­cal­ly con­cise if ( $x < $y <= $z ) {...}rather than if ( $x < $y and $y <= $z ) {...}.

Perl 5.34(2021)

Finally, we come to last week’s releaseand its intro­duc­tion of exper­i­men­tal try/​catchexcep­tion han­dling syn­tax. If you need to sup­port ear­li­er ver­sions of Perl back to 5.14, you can use Feature::Compat::Try. Earlier this year I inter­viewed the fea­ture and mod­ule’s author, Paul ​“LeoNerd” Evans, for Perl.com. This year also marked the debut of Perl’s new gov­er­nance mod­elwith the appoint­ment of a Core Teamand a three-​member Steering Council.

What are some of your favorite Perl improve­ments over the years?Check out the perlhistdoc­u­mentfor a detailed chronol­o­gy and refresh­er with the var­i­ous perldeltapagesand leave me a com­ment below.


Discover more from The Phoenix Trap

Subscribe to get the latest posts sent to your email.

Mark Gardner Avatar

Hi, I’m Mark.

Hi, I’m Mark Gard­ner, and this is my personal blog. I show software developers how to level up by building production-ready things that work. Clear code, real projects, lessons learned.

Comments

3 responses to “Perl can do that now!”

  1. Robert H Avatar
    Robert H

    Good stuff!

  2. […] This is a great and quick overview of what has been added in perl the last cou­ple of releas­es: https://phoenixtrap-com.us.stackstaging.com/2021/05/25/perl-can-do-that-now/[…]

  3. Mark Gardner Avatar

    @smxi @RL_Dane @benjaminhollon @sotolfNobody out­side of #sysad­minslook­ing for a bet­ter #sedor #awkpaid atten­tion to #Perl3. Late Perl 4 to ear­ly #Perl5was when the web took off and it became the go-​to for (most­ly half-​assed) #CGIscripts, so much so that its main­tain­ers includ­ed the mono­lith­ic CGI mod­ule from ver­sion 5.004 (5.4) to 5.20.If you haven’t looked at the lan­guage much since v5.10 I’d invite you to a blog I wrote about some of the high­lights since then: https://phoenixtrap-com.us.stackstaging.com/2021/05/25/perl-can-do-that-now/
    awk
    cgi
    perl
    perl5
    sed
    sysad­mins
    Perl can do that now!—The Phoenix Trap

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn more about Webmentions.