Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a function based on the version of perl?

I'm sorry if this had been asked, but I found it hard to search for.

I use Perl 5.12 locally but some of our machines use Perl 5.8.8 and they won't be updated for the time being.

For auditing I use 'say' on platform 5.12.

I've written a simple function to implement say on 5.8.8 but I don't want to use it on 5.12.

Is there a way to only use my say function on the older version of Perl and use the 'builtin' version of say on 5.12?

like image 243
chollida Avatar asked Mar 22 '11 16:03

chollida


1 Answers

You can use the $^V special variable to determine the version of the Perl interpreter:

BEGIN {
    if ($^V ge v5.10.1) {  # "say" first appeared in 5.10
        require feature;
        feature->import('say');
    }
    else {
        *say = sub { print @_, "\n" }
    }    
}
like image 103
Eugene Yarmash Avatar answered Sep 25 '22 01:09

Eugene Yarmash