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 'bu开发者_如何学Goiltin' version of say on 5.12?
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" }
}
}
This should work:
BEGIN{
no warnings 'once';
unless( eval{
require feature;
feature->import('say');
1
} ){
*say = sub{
print @_, "\n";
}
}
}
精彩评论