要确保脚本至少具有perl的X版本,您可以执行以下操作
require 5.6.8;
检查版本不是太近的最佳方法是什么? (即版本5.8.x,如果罚款,但5.9或5.10不行)。
答案 0 :(得分:23)
如果Perl的版本大于5.8.9:
,此代码将会死亡die "woah, that is a little too new" unless $] <= 5.008009;
您可以在perldoc perlvar
中详细了解$]
。
答案 1 :(得分:8)
您可以使用特殊的$^V
变量来检查版本。来自perldoc perlvar:
$^V
The revision, version, and subversion of the Perl interpreter, represented as a
version object.
This variable first appeared in perl 5.6.0; earlier versions of perl will see an
undefined value. Before perl 5.10.0 $^V was represented as a v-string.
您可以在字符串比较中使用$ ^ V,例如
if ( $^V lt 'v5.10.0' )
如果您运行的是早于5.6.0的perl,则需要使用返回简单整数的$]
。
答案 2 :(得分:0)
最简单的解决方案是:
no 5.010;