How can I check that a perl version is not greater than some value?

谁说我不能喝 提交于 2020-02-02 03:09:33

问题


To ensure a script has at least version X of perl, you can do the following

require 5.6.8;

What is the best way of checking that a version is not too recent? (i.e. version 5.8.x if fine, but 5.9 or 5.10 are not ok).


回答1:


This code will die if the version of Perl is greater than 5.8.9:

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

You can read more about $] in perldoc perlvar.




回答2:


You can use the special $^V variable to check the version. From 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.

You can use $^V in a string comparison, e.g.

if ( $^V lt 'v5.10.0' )

If you may be running on a perl earlier than 5.6.0, you'll need to use $] which returns a simple integer.




回答3:


The simplest solution would be to do this:

no 5.010;


来源:https://stackoverflow.com/questions/1377469/how-can-i-check-that-a-perl-version-is-not-greater-than-some-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!