# Parsing version strings (decimal or dotted-decimal)
use version 0.77; # get latest bug-fixes and API
$ver = version->parse($string)
# Declaring a dotted-decimal $VERSION (keep on one line!)
use version; our $VERSION = version->declare("v1.2.3"); # formal
use version; our $VERSION = qv("v1.2.3"); # deprecated
use version; our $VERSION = qv("v1.2_3"); # deprecated
# Declaring an old-style decimal $VERSION (use quotes!)
our $VERSION = "1.0203"; # recommended
use version; our $VERSION = version->parse("1.0203"); # formal
use version; our $VERSION = version->parse("1.02_03"); # alpha
# Comparing mixed version styles (decimals, dotted-decimals, objects)
if ( version->parse($v1) == version->parse($v2) ) {
# do stuff
}
# Sorting mixed version styles
@ordered = sort { version->parse($a) <=> version->parse($b) } @list;
use version 0.77; # even for Perl v.5.10.0
our $VERSION = "1.02";
Since Perl v5.10.0 includes the version.pm comparison logic anyways, you don't need to do anything at all.
Important Note: you must ensure that your new $VERSION is numerically greater than your current decimal $VERSION; this is not always obvious. First, convert your old decimal version (e.g. 1.02) to a normalized dotted-decimal form:
$ perl -Mversion -e 'print version->parse("1.02")->normal'
v1.20.0
Then increment any of the dotted-decimal components (v1.20.1 or v1.21.0).
use version; our $VERSION = version->declare("v1.2.3");
The "declare()" method always creates dotted-decimal version objects. When used in a module, you must put it on the same line as ``use version'' to ensure that $VERSION is read correctly by PAUSE and installer tools. You should also add 'version' to the 'configure_requires' section of your module metadata file. See instructions in ExtUtils::MakeMaker or Module::Build for details.
Important Note: Even if you pass in what looks like a decimal number (``1.2''), a dotted-decimal will be created (``v1.200.0''). To avoid confusion or unintentional errors on older Perls, follow these guidelines:
If you really insist on using version.pm with an ordinary decimal version, use "parse()" instead of declare. See the ``PARSING AND COMPARING VERSIONS'' for details.
See also version::Internals for more on version number conversion, quoting, calculated version numbers and declaring developer or ``alpha'' version numbers.
Some examples:
$variable version->parse($variable) --------- ------------------------- 1.23 v1.230.0 "1.23" v1.230.0 v1.23 v1.23.0 "v1.23" v1.23.0 "1.2.3" v1.2.3 "v1.2.3" v1.2.3
See version::Internals for more on version number conversion.
v1.2
1.2345.6
v1.23_4
1.2345
1.2345_01
v1.234.5
2.3456
See version::Internals for details of the regular expressions that define the legal version string forms, as well as how to use those regular expressions in your own code if "is_lax()" and "is_strict()" are not sufficient for your needs.
if ( version->parse($v1) == version->parse($v2) ) {
# do stuff
}
If a version object is compared against a non-version object, the non-object term will be converted to a version object using "parse()". This may give surprising results:
$v1 = version->parse("v0.95.0");
$bool = $v1 < 0.94; # TRUE since 0.94 is v0.940.0
Always comparing to a version object will help avoid surprises:
$bool = $v1 < version->parse("v0.94.0"); # FALSE
Note that ``alpha'' version objects (where the version string contains a trailing underscore segment) compare as less than the equivalent version without an underscore:
$bool = version->parse("1.23_45") < version->parse("1.2345"); # TRUE
See version::Internals for more details on ``alpha'' versions.
version->parse('1.002_03')->is_alpha; # TRUE
version->declare('1.2.3_4')->is_alpha; # TRUE
version->parse('v1.2.0')->is_qv; # TRUE
version->declare('v1.2')->is_qv; # TRUE
qv('1.2')->is_qv; # TRUE
version->parse('1.2')->is_qv; # FALSE
version->declare('v1.2')->normal; # v1.2.0
version->parse('1.2')->normal; # v1.200.0
version->declare('v1.2')->numify; # 1.002000
version->parse('1.2')->numify; # 1.200
version->declare('v1.2')->stringify; # v1.2
version->parse('1.200')->stringify; # 1.2
version->parse(1.02_30)->stringify; # 1.023
use version 0.77 ();
This function takes a scalar argument and returns a boolean value indicating whether the argument meets the ``lax'' rules for a version number. Leading and trailing spaces are not allowed.
This function takes a scalar argument and returns a boolean value indicating whether the argument meets the ``strict'' rules for a version number. Leading and trailing spaces are not allowed.
perl.