Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Will 'when()' be removed or deprecated in upcoming version of Perl?

by Darkwing (Beadle)
on Jun 22, 2018 at 06:57 UTC ( [id://1217163]=perlquestion: print w/replies, xml ) Need Help??

Darkwing has asked for the wisdom of the Perl Monks concerning the following question:

Every now and then i use something this in my code:
for ($foo) { when (/blah/) {...} when (/xyz/) {...} ... }
Now this page Beware of the removal of when in Perl v5.28 tells that when() will be removed in perl 5.28, meaning that i would need to change such code. But on this page perldeprecation there is nothing written about removing when() or marking it deprecated. Now, what is correct about the when()?

Replies are listed 'Best First'.
Re: Will 'when()' be removed or deprecated in upcoming version of Perl?
by kcott (Archbishop) on Jun 22, 2018 at 08:08 UTC

    G'day Darkwing,

    "Now this page Beware of the removal of when in Perl v5.28 tells that when() will be removed in perl 5.28, ..."

    Well, it doesn't actually say it will be removed, rather to beware of its removal. Yes, I know, it's a subtle distinction.

    If you look at the abstract, you'll see "... I haven’t seen an official notice ...", followed by "... by popular outcry these changes won’t be in v5.28.". Also note that the article is about six months old.

    Perl 5.28 is currently at RC4 (RC=Release Candidate), and when is still there. I would, however, draw your attention to "perlsyn: Experimental Details on given and when" (from 5.28-RC4). Note phrases like "highly experimental" and "subject to change with little notice" whilst reading that section.

    At the end of the day, you shouldn't be using any experimental features in production code. Of course, this particular feature is a little tricky in that regard. It was introduced in 5.10 and many, myself included, used it. But, in 5.18 it was made experimental: "perl5180delta: The smartmatch family of features are now experimental".

    I'd advise not using it in any commercial or production grade code; and being aware of potential problems when using it elsewhere.

    — Ken

Re: Will 'when()' be removed or deprecated in upcoming version of Perl?
by haukex (Archbishop) on Jun 22, 2018 at 07:48 UTC
    Will 'when()' be removed or deprecated in upcoming version of Perl?

    Looking at the latest v5.28.0-RC4's perldelta, perldeprecation, and perlexperiment, the answer is no, smart matching and given/when are not going to change in v5.28.

    However, they are still experimental, and so it's still very much possible they may undergo major changes or be removed in a future version. I would strongly recommend avoiding them. The simplest replacement (although not necessarily the prettiest) is if/elsif chains, but there are also several modules on CPAN - just beware of Switch and other modules that make use of source filters.

Re: Will 'when()' be removed or deprecated in upcoming version of Perl?
by taint (Chaplain) on Jun 22, 2018 at 18:57 UTC
    The two replies by haukex, and kcott, are very good, and pretty well cover it.

    I would only add that; if you find you're really hooked on when, and it get's nuked. You could always make it a sub, or export it from an earlier Perl release, and turn it into a CPAN module. :-)

    --Chris

    Evil is good, for without it, Good would have no value
    ¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1217163]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found