Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Conditionally executing different code based on Perl Version

by tobyink (Abbot)
on Feb 21, 2012 at 22:05 UTC ( #955400=note: print w/ replies, xml ) Need Help??


in reply to Conditionally executing different code based on Perl Version

The previous answer should work nicely for your particular case. For the more general case,

if ($] >= 5.014) { ... } else { ... }

will often work. However, in some cases you'll have code that while OK in one version of Perl, will result in a compile-time error in another. In those cases, you may need to protect Perl from your code using a stringy eval, or placing the code in external files and conditionally requireing them.

The $] >= 5.014 can probably be optimized by declaring a constant at BEGIN time:

BEGIN { *NEW_PERL = ($] >= 5.014) ? sub(){1} : sub(){0}; } ... if (NEW_PERL) { ... } else { ... }


Comment on Re: Conditionally executing different code based on Perl Version
Select or Download Code
Re^2: Conditionally executing different code based on Perl Version
by dlarochelle (Sexton) on Feb 21, 2012 at 22:29 UTC

    Thanks Eliya and tobyink.

    This is exactly what I was looking for!

Re^2: Conditionally executing different code based on Perl Version
by JavaFan (Canon) on Feb 22, 2012 at 08:42 UTC
    Note that none of your suggestions actually works for the OP. He cannot use use re '/d'; in code that's compiled under 5.12 or earlier, and since its effect is scope based, putting it inside an eval isn't going to help either, as an eval creates its own scope.

    What may work is:

    require re; re->import('/d') if $] >= 5.014;
    but I have not tested this.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://955400]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (14)
As of 2014-07-22 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (119 votes), past polls