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 { ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Conditionally executing different code based on Perl Version
by dlarochelle (Sexton) on Feb 21, 2012 at 22:29 UTC | |
|
Re^2: Conditionally executing different code based on Perl Version
by JavaFan (Canon) on Feb 22, 2012 at 08:42 UTC |