CINXE.COM
version - Perl extension for Version Objects - Perldoc Browser
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>version - Perl extension for Version Objects - Perldoc Browser</title> <link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser"> <link rel="canonical" href="https://perldoc.perl.org/version"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" /> <style> body { background: #f4f4f5; color: #020202; } .navbar-dark { background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%); background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%); background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0); background-repeat: repeat-x; } .navbar-dark .navbar-nav .nav-link, .navbar-dark .navbar-nav .nav-link:focus { color: #fff } .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 } #wrapperlicious { margin: 0 auto; font: 0.9em 'Helvetica Neue', Helvetica, sans-serif; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0; } #wrapperlicious h1 { font-size: 1.5em } #wrapperlicious h2 { font-size: 1.3em } #wrapperlicious h3 { font-size: 1.1em } #wrapperlicious h4 { font-size: 0.9em } #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3, #wrapperlicious h4, #wrapperlicious dt { color: #020202; margin-top: 1em; margin-bottom: 1em; position: relative; font-weight: bold; } #wrapperlicious a { color: inherit; text-decoration: underline } #wrapperlicious #toc { text-decoration: none } #wrapperlicious a:hover { color: #2a2a2a } #wrapperlicious a img { border: 0 } #wrapperlicious :not(pre) > code { color: inherit; background-color: rgba(0, 0, 0, 0.04); border-radius: 3px; font: 0.9em Consolas, Menlo, Monaco, monospace; padding: 0.3em; } #wrapperlicious dd { margin: 0; margin-left: 2em; } #wrapperlicious dt { color: #2a2a2a; font-weight: bold; margin-left: 0.9em; } #wrapperlicious p { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious li > p { margin-bottom: 0; margin-top: 0; } #wrapperlicious pre { border: 1px solid #c1c1c1; border-radius: 3px; font: 100% Consolas, Menlo, Monaco, monospace; margin-bottom: 1em; margin-top: 1em; } #wrapperlicious pre > code { display: block; background-color: #f6f6f6; font: 0.9em Consolas, Menlo, Monaco, monospace; line-height: 1.5em; text-align: left; white-space: pre; padding: 1em; } #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious ul { list-style-type: square; } #wrapperlicious ul ul { margin-bottom: 0px; margin-top: 0px; } #footer { font-size: 0.8em; padding-top: 0.5em; text-align: center; } #more { display: inline; font-size: 0.8em; } #perldocdiv { background-color: #fff; border: 1px solid #c1c1c1; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; margin-left: auto; margin-right: auto; padding: 3em; padding-top: 1em; max-width: 960px; } #moduleversion { float: right } #wrapperlicious .leading-notice { font-style: italic; padding-left: 1em; margin-top: 1em; margin-bottom: 1em; } #wrapperlicious .permalink { display: none; left: -0.75em; position: absolute; padding-right: 0.25em; text-decoration: none; } #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink, #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink, #wrapperlicious dt:hover .permalink { display: block; } </style> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-KVNWBNT5FB'); gtag('config', 'UA-50555-3'); </script> </head> <body> <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand" href="/"><img src="/images/perl_camel_30.png" width="30" height="30" class="d-inline-block align-top" alt="Perl Camel Logo"> Perldoc Browser</a> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav mr-auto"> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.36.2</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-stable"> <a class="dropdown-item" href="/version">Latest</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1/version">5.40.1</a> <a class="dropdown-item" href="/5.40.0/version">5.40.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3/version">5.38.3</a> <a class="dropdown-item" href="/5.38.2/version">5.38.2</a> <a class="dropdown-item" href="/5.38.1/version">5.38.1</a> <a class="dropdown-item" href="/5.38.0/version">5.38.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.36.3/version">5.36.3</a> <a class="dropdown-item active" href="/5.36.2/version">5.36.2</a> <a class="dropdown-item" href="/5.36.1/version">5.36.1</a> <a class="dropdown-item" href="/5.36.0/version">5.36.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.34.3/version">5.34.3</a> <a class="dropdown-item" href="/5.34.2/version">5.34.2</a> <a class="dropdown-item" href="/5.34.1/version">5.34.1</a> <a class="dropdown-item" href="/5.34.0/version">5.34.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.32.1/version">5.32.1</a> <a class="dropdown-item" href="/5.32.0/version">5.32.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.30.3/version">5.30.3</a> <a class="dropdown-item" href="/5.30.2/version">5.30.2</a> <a class="dropdown-item" href="/5.30.1/version">5.30.1</a> <a class="dropdown-item" href="/5.30.0/version">5.30.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.28.3/version">5.28.3</a> <a class="dropdown-item" href="/5.28.2/version">5.28.2</a> <a class="dropdown-item" href="/5.28.1/version">5.28.1</a> <a class="dropdown-item" href="/5.28.0/version">5.28.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.26.3/version">5.26.3</a> <a class="dropdown-item" href="/5.26.2/version">5.26.2</a> <a class="dropdown-item" href="/5.26.1/version">5.26.1</a> <a class="dropdown-item" href="/5.26.0/version">5.26.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.24.4/version">5.24.4</a> <a class="dropdown-item" href="/5.24.3/version">5.24.3</a> <a class="dropdown-item" href="/5.24.2/version">5.24.2</a> <a class="dropdown-item" href="/5.24.1/version">5.24.1</a> <a class="dropdown-item" href="/5.24.0/version">5.24.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.22.4/version">5.22.4</a> <a class="dropdown-item" href="/5.22.3/version">5.22.3</a> <a class="dropdown-item" href="/5.22.2/version">5.22.2</a> <a class="dropdown-item" href="/5.22.1/version">5.22.1</a> <a class="dropdown-item" href="/5.22.0/version">5.22.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.20.3/version">5.20.3</a> <a class="dropdown-item" href="/5.20.2/version">5.20.2</a> <a class="dropdown-item" href="/5.20.1/version">5.20.1</a> <a class="dropdown-item" href="/5.20.0/version">5.20.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.18.4/version">5.18.4</a> <a class="dropdown-item" href="/5.18.3/version">5.18.3</a> <a class="dropdown-item" href="/5.18.2/version">5.18.2</a> <a class="dropdown-item" href="/5.18.1/version">5.18.1</a> <a class="dropdown-item" href="/5.18.0/version">5.18.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.16.3/version">5.16.3</a> <a class="dropdown-item" href="/5.16.2/version">5.16.2</a> <a class="dropdown-item" href="/5.16.1/version">5.16.1</a> <a class="dropdown-item" href="/5.16.0/version">5.16.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.14.4/version">5.14.4</a> <a class="dropdown-item" href="/5.14.3/version">5.14.3</a> <a class="dropdown-item" href="/5.14.2/version">5.14.2</a> <a class="dropdown-item" href="/5.14.1/version">5.14.1</a> <a class="dropdown-item" href="/5.14.0/version">5.14.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.12.5/version">5.12.5</a> <a class="dropdown-item" href="/5.12.4/version">5.12.4</a> <a class="dropdown-item" href="/5.12.3/version">5.12.3</a> <a class="dropdown-item" href="/5.12.2/version">5.12.2</a> <a class="dropdown-item" href="/5.12.1/version">5.12.1</a> <a class="dropdown-item" href="/5.12.0/version">5.12.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.10.1/version">5.10.1</a> <a class="dropdown-item" href="/5.10.0/version">5.10.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.9/version">5.8.9</a> <a class="dropdown-item" href="/5.8.8/version">5.8.8</a> <a class="dropdown-item" href="/5.8.7/version">5.8.7</a> <a class="dropdown-item" href="/5.8.6/version">5.8.6</a> <a class="dropdown-item" href="/5.8.5/version">5.8.5</a> <a class="dropdown-item" href="/5.8.4/version">5.8.4</a> <a class="dropdown-item" href="/5.8.3/version">5.8.3</a> <a class="dropdown-item" href="/5.8.2/version">5.8.2</a> <a class="dropdown-item" href="/5.8.1/version">5.8.1</a> <a class="dropdown-item" href="/5.8.0/version">5.8.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.6.2/version">5.6.2</a> <a class="dropdown-item" href="/5.6.1/version">5.6.1</a> <a class="dropdown-item" href="/5.6.0/version">5.6.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.005_04/version">5.005_04</a> <a class="dropdown-item" href="/5.005_03/version">5.005_03</a> <a class="dropdown-item" href="/5.005_02/version">5.005_02</a> <a class="dropdown-item" href="/5.005_01/version">5.005_01</a> <a class="dropdown-item" href="/5.005/version">5.005</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-dev"> <a class="dropdown-item" href="/blead/version">blead</a> <a class="dropdown-item" href="/5.41.10/version">5.41.10</a> <a class="dropdown-item" href="/5.41.9/version">5.41.9</a> <a class="dropdown-item" href="/5.41.8/version">5.41.8</a> <a class="dropdown-item" href="/5.41.7/version">5.41.7</a> <a class="dropdown-item" href="/5.41.6/version">5.41.6</a> <a class="dropdown-item" href="/5.41.5/version">5.41.5</a> <a class="dropdown-item" href="/5.41.4/version">5.41.4</a> <a class="dropdown-item" href="/5.41.3/version">5.41.3</a> <a class="dropdown-item" href="/5.41.2/version">5.41.2</a> <a class="dropdown-item" href="/5.41.1/version">5.41.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1-RC1/version">5.40.1-RC1</a> <a class="dropdown-item" href="/5.40.0-RC2/version">5.40.0-RC2</a> <a class="dropdown-item" href="/5.40.0-RC1/version">5.40.0-RC1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.39.10/version">5.39.10</a> <a class="dropdown-item" href="/5.39.9/version">5.39.9</a> <a class="dropdown-item" href="/5.39.8/version">5.39.8</a> <a class="dropdown-item" href="/5.39.7/version">5.39.7</a> <a class="dropdown-item" href="/5.39.6/version">5.39.6</a> <a class="dropdown-item" href="/5.39.5/version">5.39.5</a> <a class="dropdown-item" href="/5.39.4/version">5.39.4</a> <a class="dropdown-item" href="/5.39.3/version">5.39.3</a> <a class="dropdown-item" href="/5.39.2/version">5.39.2</a> <a class="dropdown-item" href="/5.39.1/version">5.39.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3-RC1/version">5.38.3-RC1</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-nav"> <a class="dropdown-item" href="/5.36.2/perl">Perl</a> <a class="dropdown-item" href="/5.36.2/perlintro">Intro</a> <a class="dropdown-item" href="/5.36.2/perl#Tutorials">Tutorials</a> <a class="dropdown-item" href="/5.36.2/perlfaq">FAQs</a> <a class="dropdown-item" href="/5.36.2/perl#Reference-Manual">Reference</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.36.2/perlop">Operators</a> <a class="dropdown-item" href="/5.36.2/functions">Functions</a> <a class="dropdown-item" href="/5.36.2/variables">Variables</a> <a class="dropdown-item" href="/5.36.2/modules">Modules</a> <a class="dropdown-item" href="/5.36.2/perlutil">Utilities</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.36.2/perldelta">Release Notes</a> <a class="dropdown-item" href="/5.36.2/perlcommunity">Community</a> <a class="dropdown-item" href="/5.36.2/perlhist">History</a> </div> </li> </ul> <ul class="navbar-nav"> <script> function set_expand (expand) { var perldocdiv = document.getElementById('perldocdiv'); var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width'); var expanded = (width == '' || width == 'none') ? true : false; if (expand === null) { expand = !expanded; } if ((expand && !expanded) || (!expand && expanded)) { perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px'); var button_classlist = document.getElementById('content-expand-button').classList; if (expand) { button_classlist.add('btn-light'); button_classlist.remove('btn-outline-light'); } else { button_classlist.add('btn-outline-light'); button_classlist.remove('btn-light'); } } return expand; } function toggle_expand () { var expand = set_expand(null); document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC'; } function read_expand () { return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function () { if (read_expand()) { set_expand(true); } }); } else if (read_expand()) { set_expand(true); } </script> <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-4" onclick="toggle_expand()">Expand</button> </ul> <form class="form-inline" method="get" action="/5.36.2/search"> <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search" value=""> </form> </div> </nav> <div id="wrapperlicious" class="container-fluid"> <div id="perldocdiv"> <div id="links"> <a href="/5.36.2/version">version</a> <div id="more"> (<a href="/5.36.2/version.txt">source</a>, <a href="https://metacpan.org/pod/version">CPAN</a>) </div> <div id="moduleversion">version 0.9929</div> </div> <div class="leading-notice"> You are viewing the version of this documentation from Perl 5.36.2. <a href="/version">View the latest version</a> </div> <h1><a id="toc">CONTENTS</a></h1> <ul> <li> <a class="text-decoration-none" href="#NAME">NAME</a> </li> <li> <a class="text-decoration-none" href="#SYNOPSIS">SYNOPSIS</a> </li> <li> <a class="text-decoration-none" href="#DESCRIPTION">DESCRIPTION</a> </li> <li> <a class="text-decoration-none" href="#TYPES-OF-VERSION-OBJECTS">TYPES OF VERSION OBJECTS</a> </li> <li> <a class="text-decoration-none" href="#DECLARING-VERSIONS">DECLARING VERSIONS</a> <ul> <li> <a class="text-decoration-none" href="#How-to-convert-a-module-from-decimal-to-dotted-decimal">How to convert a module from decimal to dotted-decimal</a> </li> <li> <a class="text-decoration-none" href="#How-to-declare()-a-dotted-decimal-version">How to declare() a dotted-decimal version</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#PARSING-AND-COMPARING-VERSIONS">PARSING AND COMPARING VERSIONS</a> <ul> <li> <a class="text-decoration-none" href="#How-to-parse()-a-version">How to parse() a version</a> </li> <li> <a class="text-decoration-none" href="#How-to-check-for-a-legal-version-string">How to check for a legal version string</a> </li> <li> <a class="text-decoration-none" href="#How-to-compare-version-objects">How to compare version objects</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#OBJECT-METHODS">OBJECT METHODS</a> <ul> <li> <a class="text-decoration-none" href="#is_alpha()">is_alpha()</a> </li> <li> <a class="text-decoration-none" href="#is_qv()">is_qv()</a> </li> <li> <a class="text-decoration-none" href="#normal()">normal()</a> </li> <li> <a class="text-decoration-none" href="#numify()">numify()</a> </li> <li> <a class="text-decoration-none" href="#stringify()">stringify()</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#EXPORTED-FUNCTIONS">EXPORTED FUNCTIONS</a> <ul> <li> <a class="text-decoration-none" href="#qv()">qv()</a> </li> <li> <a class="text-decoration-none" href="#is_lax()1">is_lax()</a> </li> <li> <a class="text-decoration-none" href="#is_strict()1">is_strict()</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#AUTHOR">AUTHOR</a> </li> <li> <a class="text-decoration-none" href="#SEE-ALSO">SEE ALSO</a> </li> </ul> <h1 id="NAME"><a class="permalink" href="#NAME">#</a>NAME</h1> <p>version - Perl extension for Version Objects</p> <h1 id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">#</a>SYNOPSIS</h1> <pre><code># 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;</code></pre> <h1 id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">#</a>DESCRIPTION</h1> <p>Version objects were added to Perl in 5.10. This module implements version objects for older version of Perl and provides the version object API for all versions of Perl. All previous releases before 0.74 are deprecated and should not be used due to incompatible API changes. Version 0.77 introduces the new 'parse' and 'declare' methods to standardize usage. You are strongly urged to set 0.77 as a minimum in your code, e.g.</p> <pre><code>use version 0.77; # even for Perl v.5.10.0</code></pre> <h1 id="TYPES-OF-VERSION-OBJECTS"><a class="permalink" href="#TYPES-OF-VERSION-OBJECTS">#</a><a id="TYPES"></a>TYPES OF VERSION OBJECTS</h1> <p>There are two different types of version objects, corresponding to the two different styles of versions in use:</p> <dl> <dt id="Decimal-Versions"><a class="permalink" href="#Decimal-Versions">#</a><a id="Decimal"></a>Decimal Versions</dt> <dd> <p>The classic floating-point number $VERSION. The advantage to this style is that you don't need to do anything special, just type a number into your source file. Quoting is recommended, as it ensures that trailing zeroes ("1.50") are preserved in any warnings or other output.</p> </dd> <dt id="Dotted-Decimal-Versions"><a class="permalink" href="#Dotted-Decimal-Versions">#</a><a id="Dotted"></a>Dotted Decimal Versions</dt> <dd> <p>The more modern form of version assignment, with 3 (or potentially more) integers separated by decimal points (e.g. v1.2.3). This is the form that Perl itself has used since 5.6.0 was released. The leading 'v' is now strongly recommended for clarity, and will throw a warning in a future release if omitted. A leading 'v' character is required to pass the <a href="#is_strict()">"is_strict()"</a> test.</p> </dd> </dl> <h1 id="DECLARING-VERSIONS"><a class="permalink" href="#DECLARING-VERSIONS">#</a><a id="DECLARING"></a>DECLARING VERSIONS</h1> <p>If you have a module that uses a decimal $VERSION (floating point), and you do not intend to ever change that, this module is not for you. There is nothing that version.pm gains you over a simple $VERSION assignment:</p> <pre><code>our $VERSION = "1.02";</code></pre> <p>Since Perl v5.10.0 includes the version.pm comparison logic anyways, you don't need to do anything at all.</p> <h2 id="How-to-convert-a-module-from-decimal-to-dotted-decimal"><a class="permalink" href="#How-to-convert-a-module-from-decimal-to-dotted-decimal">#</a><a id="How"></a>How to convert a module from decimal to dotted-decimal</h2> <p>If you have used a decimal $VERSION in the past and wish to switch to a dotted-decimal $VERSION, then you need to make a one-time conversion to the new format.</p> <p><b>Important Note</b>: 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:</p> <pre><code>$ perl -Mversion -e 'print version->parse("1.02")->normal' v1.20.0</code></pre> <p>Then increment any of the dotted-decimal components (v1.20.1 or v1.21.0).</p> <h2 id="How-to-declare()-a-dotted-decimal-version"><a class="permalink" href="#How-to-declare()-a-dotted-decimal-version">#</a><a id="How1"></a><a id="How-to-declare-a-dotted-decimal-version"></a>How to <code>declare()</code> a dotted-decimal version</h2> <pre><code>use version; our $VERSION = version->declare("v1.2.3");</code></pre> <p>The <code>declare()</code> method always creates dotted-decimal version objects. When used in a module, you <b>must</b> 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 <a href="/5.36.2/ExtUtils::MakeMaker">ExtUtils::MakeMaker</a> or <a href="/5.36.2/Module::Build">Module::Build</a> for details.</p> <p><b>Important Note</b>: 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:</p> <ul> <li><p>Always use a dotted-decimal with (at least) three components</p> </li> <li><p>Always use a leading-v</p> </li> <li><p>Always quote the version</p> </li> </ul> <p>If you really insist on using version.pm with an ordinary decimal version, use <code>parse()</code> instead of declare. See the <a href="#PARSING-AND-COMPARING-VERSIONS">"PARSING AND COMPARING VERSIONS"</a> for details.</p> <p>See also <a href="/5.36.2/version::Internals">version::Internals</a> for more on version number conversion, quoting, calculated version numbers and declaring developer or "alpha" version numbers.</p> <h1 id="PARSING-AND-COMPARING-VERSIONS"><a class="permalink" href="#PARSING-AND-COMPARING-VERSIONS">#</a><a id="PARSING"></a>PARSING AND COMPARING VERSIONS</h1> <p>If you need to compare version numbers, but can't be sure whether they are expressed as numbers, strings, v-strings or version objects, then you should use version.pm to parse them all into objects for comparison.</p> <h2 id="How-to-parse()-a-version"><a class="permalink" href="#How-to-parse()-a-version">#</a><a id="How2"></a><a id="How-to-parse-a-version"></a>How to <code>parse()</code> a version</h2> <p>The <code>parse()</code> method takes in anything that might be a version and returns a corresponding version object, doing any necessary conversion along the way.</p> <ul> <li><p>Dotted-decimal: bare v-strings (v1.2.3) and strings with more than one decimal point and a leading 'v' ("v1.2.3"); NOTE you can technically use a v-string or strings with a leading-v and only one decimal point (v1.2 or "v1.2"), but you will confuse both yourself and others.</p> </li> <li><p>Decimal: regular decimal numbers (literal or in a string)</p> </li> </ul> <p>Some examples:</p> <pre><code>$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</code></pre> <p>See <a href="/5.36.2/version::Internals">version::Internals</a> for more on version number conversion.</p> <h2 id="How-to-check-for-a-legal-version-string"><a class="permalink" href="#How-to-check-for-a-legal-version-string">#</a><a id="How3"></a>How to check for a legal version string</h2> <p>If you do not want to actually create a full blown version object, but would still like to verify that a given string meets the criteria to be parsed as a version, there are two helper functions that can be employed directly:</p> <dl> <dt id="is_lax()"><a class="permalink" href="#is_lax()">#</a><a id="is_lax"></a><code>is_lax()</code></dt> <dd> <p>The lax criteria corresponds to what is currently allowed by the version parser. All of the following formats are acceptable for dotted-decimal formats strings:</p> <pre><code class="plaintext">v1.2 1.2345.6 v1.23_4 1.2345 1.2345_01</code></pre> </dd> <dt id="is_strict()"><a class="permalink" href="#is_strict()">#</a><a id="is_strict"></a><code>is_strict()</code></dt> <dd> <p>If you want to limit yourself to a much more narrow definition of what a version string constitutes, <code>is_strict()</code> is limited to version strings like the following list:</p> <pre><code class="plaintext">v1.234.5 2.3456</code></pre> </dd> </dl> <p>See <a href="/5.36.2/version::Internals">version::Internals</a> 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 <code>is_lax()</code> and <code>is_strict()</code> are not sufficient for your needs.</p> <h2 id="How-to-compare-version-objects"><a class="permalink" href="#How-to-compare-version-objects">#</a><a id="How4"></a>How to compare version objects</h2> <p>Version objects overload the <code>cmp</code> and <code><=></code> operators. Perl automatically generates all of the other comparison operators based on those two so all the normal logical comparisons will work.</p> <pre><code>if ( version->parse($v1) == version->parse($v2) ) { # do stuff }</code></pre> <p>If a version object is compared against a non-version object, the non-object term will be converted to a version object using <code>parse()</code>. This may give surprising results:</p> <pre><code>$v1 = version->parse("v0.95.0"); $bool = $v1 < 0.94; # TRUE since 0.94 is v0.940.0</code></pre> <p>Always comparing to a version object will help avoid surprises:</p> <pre><code>$bool = $v1 < version->parse("v0.94.0"); # FALSE</code></pre> <p>Note that "alpha" version objects (where the version string contains a trailing underscore segment) compare as less than the equivalent version without an underscore:</p> <pre><code>$bool = version->parse("1.23_45") < version->parse("1.2345"); # TRUE</code></pre> <p>See <a href="/5.36.2/version::Internals">version::Internals</a> for more details on "alpha" versions.</p> <h1 id="OBJECT-METHODS"><a class="permalink" href="#OBJECT-METHODS">#</a><a id="OBJECT"></a>OBJECT METHODS</h1> <h2 id="is_alpha()"><a class="permalink" href="#is_alpha()">#</a><a id="is_alpha"></a>is_alpha()</h2> <p>True if and only if the version object was created with a underscore, e.g.</p> <pre><code>version->parse('1.002_03')->is_alpha; # TRUE version->declare('1.2.3_4')->is_alpha; # TRUE</code></pre> <h2 id="is_qv()"><a class="permalink" href="#is_qv()">#</a><a id="is_qv"></a>is_qv()</h2> <p>True only if the version object is a dotted-decimal version, e.g.</p> <pre><code>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</code></pre> <h2 id="normal()"><a class="permalink" href="#normal()">#</a><a id="normal"></a>normal()</h2> <p>Returns a string with a standard 'normalized' dotted-decimal form with a leading-v and at least 3 components.</p> <pre><code>version->declare('v1.2')->normal; # v1.2.0 version->parse('1.2')->normal; # v1.200.0</code></pre> <h2 id="numify()"><a class="permalink" href="#numify()">#</a><a id="numify"></a>numify()</h2> <p>Returns a value representing the object in a pure decimal.</p> <pre><code>version->declare('v1.2')->numify; # 1.002000 version->parse('1.2')->numify; # 1.200</code></pre> <h2 id="stringify()"><a class="permalink" href="#stringify()">#</a><a id="stringify"></a>stringify()</h2> <p>Returns a string that is as close to the original representation as possible. If the original representation was a numeric literal, it will be returned the way perl would normally represent it in a string. This method is used whenever a version object is interpolated into a string.</p> <pre><code>version->declare('v1.2')->stringify; # v1.2 version->parse('1.200')->stringify; # 1.2 version->parse(1.02_30)->stringify; # 1.023</code></pre> <h1 id="EXPORTED-FUNCTIONS"><a class="permalink" href="#EXPORTED-FUNCTIONS">#</a><a id="EXPORTED"></a>EXPORTED FUNCTIONS</h1> <h2 id="qv()"><a class="permalink" href="#qv()">#</a><a id="qv"></a>qv()</h2> <p>This function is no longer recommended for use, but is maintained for compatibility with existing code. If you do not want to have it exported to your namespace, use this form:</p> <pre><code>use version 0.77 ();</code></pre> <h2 id="is_lax()1"><a class="permalink" href="#is_lax()1">#</a><a id="is_lax1"></a>is_lax()</h2> <p>(Not exported by default)</p> <p>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.</p> <h2 id="is_strict()1"><a class="permalink" href="#is_strict()1">#</a><a id="is_strict1"></a>is_strict()</h2> <p>(Not exported by default)</p> <p>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.</p> <h1 id="AUTHOR"><a class="permalink" href="#AUTHOR">#</a>AUTHOR</h1> <p>John Peacock <jpeacock@cpan.org></p> <h1 id="SEE-ALSO"><a class="permalink" href="#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1> <p><a href="/5.36.2/version::Internals">version::Internals</a>.</p> <p><a href="/5.36.2/perl">perl</a>.</p> </div> <div id="footer"> <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p> <p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script> <script src="/js/highlight.pack.js"></script> <script>hljs.highlightAll();</script> </body> </html>