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 { ... }
In reply to Re: Conditionally executing different code based on Perl Version
by tobyink
in thread Conditionally executing different code based on Perl Version
by dlarochelle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |