Dpkg::Version(3perl) libdpkg-perl Dpkg::Version(3perl)

# [NAME](#NAME)

Dpkg::Version - handling and comparing dpkg-style version numbers

# [DESCRIPTION](#DESCRIPTION)

The Dpkg::Version module provides pure-Perl routines to compare dpkg-style version numbers (as used in Debian packages) and also an object oriented interface overriding perl operators to do the right thing when you compare Dpkg::Version object between them.

# [METHODS](#METHODS)

$v = Dpkg::Version-&gt;new($version, %opts)

Create a new Dpkg::Version object corresponding to the version indicated in the string (scalar) $version. By default it will accept any string and consider it as a valid version, but this can be controlled with the "check" option.

You can always call $v-&gt;**is\_valid()** later on to verify that the version is valid.

Options:

[**check**](#check)

Setting this option to true will return undef if the version is invalid (see $v-&gt;**version\_check()** for details).

[boolean evaluation](#boolean)

When the Dpkg::Version object is used in a boolean evaluation (for example in "if ($v)" or "$v ? \\"$v\\" : 'default'") it returns true if the version stored is valid ($v-&gt;**is\_valid()**) and false otherwise.

**Notice**: Between dpkg 1.15.7.2 and 1.19.1 this overload used to return $v-&gt;**as\_string()** if $v-&gt;**is\_valid()**, a breaking change in behavior that caused "0" versions to be evaluated as false. To catch any possibly intended code that relied on those semantics, this overload emitted a warning with category "Dpkg::Version::semantic\_change::overload::bool" between dpkg 1.19.1 and 1.20.0. Once fixed, or for already valid code the warning could be quiesced for that specific versions with

```
  no if $Dpkg::Version::VERSION eq '1.02',
     warnings => qw(Dpkg::Version::semantic_change::overload::bool);
    
```

added after the "use Dpkg::Version".

$bool = $v-&gt;**is\_valid()**

Returns true if the version is valid, false otherwise.

$string = $v-&gt;**epoch()**

Returns the epoch part of the full version string.

If the version parsed did not have an epoch, the value returned will be 0.

$string = $v-&gt;**version()**

Returns the upstream version part of the full version string.

$string = $v-&gt;**revision()**

Returns the revision part of the full version string.

If the version parsed did not have a revision, the value returned will be 0.

$bool = $v-&gt;**is\_native()**

Returns true if the version is native, false if it has a revision.

**Note**: On some vendors, dpkg has been made incoherent, and a native source package format can end up having a non-native version, adding to the confusion of the whole concept. And while this method would be fine to be used on vendors that have a coherent native source concept, this is not a pattern that will be portably relied on. Thus this method is being deprecated. Depending on the context, using the negated result of the $v-&gt;**has\_revision()** method might be sensible.

$v-&gt;**has\_epoch()**

Returns true if the version has an epoch, false otherwise.

$v-&gt;**has\_revision()**

Returns true if the version has a revision, false otherwise.

$cmp = $v1 &lt;=&gt; $v2

$cmp = $v1 &lt; $v2

$cmp = $v1 &lt;= $v2

$cmp = $v1 &gt; $v2

$cmp = $v1 &gt;= $v2

Numerical comparison of various versions numbers. One of the two operands needs to be a Dpkg::Version, the other one can be anything provided that its string representation is a version number.

$string = "$v"

$string = $v-&gt;as\_string(%opts)

Accepts an options %opts hash, affecting the string conversion.

Options:

[**omit\_epoch** (defaults to 0)](#omit_epoch)

Omit the epoch, if present, in the output string.

[**omit\_revision** (defaults to 0)](#omit_revision)

Omit the revision, if present, in the output string.

Returns the string representation of the version number.

# [FUNCTIONS](#FUNCTIONS)

All the functions are exported by default.

$cmp = version\_compare($a, $b)

Returns -1 if $a is earlier than $b, 0 if they are equal and 1 if $a is later than $b.

If $a or $b are not valid version numbers, it dies with an error.

$bool = version\_compare\_relation($a, $rel, $b)

Returns the result (0 or 1) of the given comparison operation. This function is implemented on top of **version\_compare()**.

Allowed values for $rel are the exported constants REL\_GT, REL\_GE, REL\_EQ, REL\_LE, REL\_LT. Use **version\_normalize\_relation()** if you have an input string containing the operator.

$rel = version\_normalize\_relation($rel\_string)

Returns the normalized constant of the relation $rel (a value among REL\_GT, REL\_GE, REL\_EQ, REL\_LE and REL\_LT). Supported relations names in input are: "gt", "ge", "eq", "le", "lt", "&gt;&gt;", "&gt;=", "=", "&lt;=", "&lt;&lt;". "&gt;" and "&lt;" are also supported but should not be used as they are obsolete aliases of "&gt;=" and "&lt;=".

$cmp = version\_compare\_string($a, $b)

String comparison function used for comparing non-numerical parts of version numbers. Returns -1 if $a is earlier than $b, 0 if they are equal and 1 if $a is later than $b.

The "~" character always sort lower than anything else. Digits sort lower than non-digits. Among remaining characters alphabetic characters (A-Z, a-z) sort lower than the other ones. Within each range, the ASCII decimal value of the character is used to sort between characters.

$cmp = version\_compare\_part($a, $b)

Compare two corresponding sub-parts of a version number (either upstream version or debian revision).

Each parameter is split by **version\_split\_digits()** and resulting items are compared together. As soon as a difference happens, it returns -1 if $a is earlier than $b, 0 if they are equal and 1 if $a is later than $b.

@items = version\_split\_digits($version)

Splits a string in items that are each entirely composed either of digits or of non-digits. For instance for "1.024~beta1+svn234" it would return ("1", ".", "024", "~beta", "1", "+svn", "234").

($ok, $msg) = version\_check($version)

$ok = version\_check($version)

Checks the validity of $version as a version number. Returns 1 in $ok if the version is valid, 0 otherwise. In the latter case, $msg contains a description of the problem with the $version scalar.

# [CHANGES](#CHANGES)

## [Version 1.05 (dpkg 1.23.3)](#Version_1.05_%28dpkg_1.23.3%29)

New methods: $v-&gt;**has\_epoch()**, $v-&gt;**has\_revision()**.

## [Version 1.04 (dpkg 1.23.0)](#Version_1.04_%28dpkg_1.23.0%29)

Deprecated method: $v-&gt;**is\_native()**.

## [Version 1.03 (dpkg 1.20.0)](#Version_1.03_%28dpkg_1.20.0%29)

Remove deprecation warning from semantic change in 1.02.

## [Version 1.02 (dpkg 1.19.1)](#Version_1.02_%28dpkg_1.19.1%29)

Semantic change: bool evaluation semantics restored to their original behavior.

## [Version 1.01 (dpkg 1.17.0)](#Version_1.01_%28dpkg_1.17.0%29)

New argument: Accept an options argument in $v-&gt;**as\_string()**.

New method: $v-&gt;**is\_native()**.

## [Version 1.00 (dpkg 1.15.6)](#Version_1.00_%28dpkg_1.15.6%29)

Mark the module as public.

2026-09-09 1.23.11-dirty

---

Document: Dpkg::Version(3perl) from dpkg 1.23.11-r1 (Chainguard OS)
Source: https://git.dpkg.org/git/dpkg/dpkg.git
