Dpkg::Version(3perl)
π Dpkg::Version(3perl) β your bestie's guide to dpkg-style version numbers
Ok so this page lives in the libdpkg-perl manual, and it's literally the glow-up you need if you've ever stared at a Debian version string like 1:2.3.4-5 and thought "what is any of this". Buckle up, bestie π
β¨ NAME β¨
Dpkg::Version β handling and comparing dpkg-style version numbers. That's it. That's the whole vibe. π
πΈ DESCRIPTION πΈ
So Dpkg::Version gives you pure-Perl routines to compare dpkg-style version numbers (the kind used in Debian packages), and ngl it also ships an object-oriented interface that overrides perl operators so that when you compare two Dpkg::Version objects against each other, it just does the right thing. No cap. π«Ά
π¦ METHODS π¦
π $v = Dpkg::Version->new($version, %opts)
Makes you a brand-new Dpkg::Version object matching the version in the string (scalar) $version. By default it's super chill and will accept any string and treat it as a valid version, but you can control that with the check option. β¨
And you can always call $v->is_valid() later on to verify that the version is actually valid. Good to have that safety net.
Options:
checkβ setting this option to true will returnundefif the version is invalid (peep$v->version_check()for the deets). π
π§ boolean evaluation
When the Dpkg::Version object gets used in a boolean evaluation (like in if ($v) or $v ? \"$v\" : 'default'), it returns true if the version stored is valid ($v->is_valid()) and false otherwise.
β οΈ Notice, and this one's important: between dpkg 1.15.7.2 and 1.19.1 this overload used to return$v->as_string()if$v->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 categoryDpkg::Version::semantic_change::overload::boolbetween 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->is_valid()
Returns true if the version is valid, false otherwise. Simple. Iconic. β¨
π $string = $v->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->version()
Returns the upstream version part of the full version string. That's the main character part, fr fr.
π $string = $v->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->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->has_revision() method might be sensible. π«
π₯ $v->has_epoch()
Returns true if the version has an epoch, false otherwise.
β $v->has_revision()
Returns true if the version has a revision, false otherwise.
π¦ comparison operators, slay
$cmp = $v1 <=> $v2
$cmp = $v1 < $v2
$cmp = $v1 <= $v2
$cmp = $v1 > $v2
$cmp = $v1 >= $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->as_string(%opts)
Accepts an options %opts hash, affecting the string conversion. So you can β¨ customize β¨ your output.
Options:
omit_epoch(defaults to0) β omit the epoch, if present, in the output string.omit_revision(defaults to0) β omit the revision, if present, in the output string.
Returns the string representation of the version number. Periodt. π
π FUNCTIONS π
All the functions are exported by default β you don't gotta ask, they just show up. π«Ά
π§ $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$aor$bare not valid version numbers, it dies with an error. So like, know your inputs bestie. π
π $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", ">>", ">=", "=", "<=", "<<". ">" and "<" are also supported but should not be used as they are obsolete aliases of ">=" and "<=". π
π $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 nitty-gritty sorting tea, so listen up:
- The
"~"character always sorts 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"). Obsessed with how clean that is. β¨
π ($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. So you get the β‘οΈ reason β‘οΈ too. π
π CHANGES π
π Version 1.05 (dpkg 1.23.3)
- New methods:
$v->has_epoch(),$v->has_revision().
π¦ Version 1.04 (dpkg 1.23.0)
- Deprecated method:
$v->is_native().
πΈ Version 1.03 (dpkg 1.20.0)
- Remove deprecation warning from semantic change in
1.02.
β Version 1.02 (dpkg 1.19.1)
- Semantic change: bool evaluation semantics restored to their original behavior.
π Version 1.01 (dpkg 1.17.0)
- New argument: Accept an options argument in
$v->as_string(). - New method:
$v->is_native().
π Version 1.00 (dpkg 1.15.6)
- Mark the module as public.
okay that's the whole page bestie, go forth and compare versions with confidence π β¨
mwah π β this was 1.23.11-dirty, dated 2026-09-09, and yeah we're still calling it Dpkg::Version(3perl). slay.
π¦ where this page comes from
- arch rolling: dpkg 1.23.11-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms