如何检查perl版本是否大于某个值?

Mat*_*ard 5 perl

要确保脚本至少具有perl的X版本,您可以执行以下操作

require 5.6.8;
Run Code Online (Sandbox Code Playgroud)

检查版本不是太近的最佳方法是什么?(即版本5.8.x如果罚款,但5.9或5.10不正常).

Cha*_*ens 23

如果Perl的版本大于5.8.9,此代码将会死亡:

die "woah, that is a little too new" unless $] <= 5.008009;
Run Code Online (Sandbox Code Playgroud)

你可以阅读更多关于$]perldoc perlvar.


fri*_*edo 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.
Run Code Online (Sandbox Code Playgroud)

您可以在字符串比较中使用$ ^ V,例如

if ( $^V lt 'v5.10.0' )
Run Code Online (Sandbox Code Playgroud)

如果你可能在早于5.6.0的perl上运行,你需要使用$]它返回一个简单的整数.

  • 如果您正在尝试使用旧的perls,那么这不是可行的方法. (3认同)