代码之家  ›  专栏  ›  技术社区  ›  Matt Sheppard

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

  •  5
  • Matt Sheppard  · 技术社区  · 16 年前

    为了确保脚本至少具有Perl的版本X,可以执行以下操作

    require 5.6.8;
    

    检查版本是否太新的最佳方法是什么? (即5.8.x版,如果可以,但5.9或5.10版不适用)。

    3 回复  |  直到 16 年前
        1
  •  23
  •   Chas. Owens    16 年前

    如果Perl版本大于5.8.9,则此代码将失效:

    die "woah, that is a little too new" unless $] <= 5.008009;
    

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

        2
  •  8
  •   Chas. Owens    16 年前

    你可以用这个特别的 $^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上运行,则需要使用 $] 它返回一个简单的整数。

        3
  •  0
  •   Leon Timmermans    16 年前

    最简单的解决方案是:

    no 5.010;