Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

perl

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).

like image 905
Matt Sheppard Avatar asked Sep 04 '09 06:09

Matt Sheppard


2 Answers

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.

like image 95
Chas. Owens Avatar answered Nov 26 '22 13:11

Chas. Owens


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.

like image 31
friedo Avatar answered Nov 26 '22 13:11

friedo