Dpkg::Version β handling and comparing dpkg-style version numbers
| Use Case | Command | Description |
|---|---|---|
| Create a version object | $v = Dpkg::Version->new('1.2.3-1') | Construct a version from a string |
| Check validity | $v->is_valid() | Returns true if version string is valid |
| Compare two versions | version_compare($a, $b) | Returns -1, 0, 1 (earlier, equal, later) |
| Compare with relation | version_compare_relation($a, REL_GT, $b) | Returns 1 if $a > $b |
| Get epoch | $v->epoch() | Epoch part (e.g., 1 for β1:2.3β) |
| Get upstream version | $v->version() | Version part without epoch/revision |
| Get revision | $v->revision() | Debian revision part |
| Check if native | $v->is_native() | True if no revision present |
| String conversion, omit epoch | $v->as_string({ omit_epoch => 1 }) | Stringify without epoch |
| Suppress semantic warning | no if $Dpkg::Version::VERSION ge '1.02', warnings => qw(...); | Quiesce bool overload deprecation |
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 objects between them.
$v = Dpkg::Version->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. If you pass the option check => 1, it will return undef if the version is invalid (see version_check for details).$v->is_valid() later to verify validity.boolean evaluation β When a Dpkg::Version object is used in boolean context (e.g., if ($v) or $v ? "$v" : 'default') it returns true if the stored version is valid ($v->is_valid()) and false otherwise.
$v->as_string() when valid, causing β0β versions to be evaluated as false. To catch any code relying on that old behaviour, this overload emits a warning with category Dpkg::Version::semantic_change::overload::bool until dpkg 1.20.x. Once fixed the warning can be quiesced with:
no if $Dpkg::Version::VERSION ge '1.02',
warnings => qw(Dpkg::Version::semantic_change::overload::bool);
$v->is_valid() β β
Returns true if the version is valid, false otherwise.$v->epoch(), $v->version(), $v->revision() β Returns the corresponding part of the full version string.$v->is_native() β π± Returns true if the version is native (no revision), false if it has a revision.$v1 <=> $v2, $v1 < $v2, $v1 <= $v2, $v1 > $v2, $v1 >= $v2 β Numerical comparison of version numbers. One operand must be a Dpkg::Version; the other can be any string that represents a version."$v", $v->as_string(), $v->as_string(%options) β Returns the string representation of the version number.
omit_epoch (default 0) β π’ Omit the epoch in the output string.omit_revision (default 0) β π§ Omit the revision in the output string.All the functions are exported by default.
version_compare($a, $b) β Returns -1 if $a is earlier than $b, 0 if equal, 1 if later. Dies if either is invalid.version_compare_relation($a, $rel, $b) β Returns the result (0 or 1) of the given comparison. Built on version_compare(). Allowed $rel values: exported constants REL_GT, REL_GE, REL_EQ, REL_LE, REL_LT.$rel = version_normalize_relation($rel_string) β Normalizes a relation string into a constant (REL_GT, β¦). Supports: βgtβ, βgeβ, βeqβ, βleβ, βltβ, β>>β, β>=β, β=β, β<=β, β<<β. β>β and β<β are also accepted but are obsolete aliases for β>=β and β<=β.version_compare_string($a, $b) β String comparison for nonβnumerical parts. Sorts β~β lowest, digits before nonβdigits, letters before other characters, then by ASCII value.version_compare_part($a, $b) β Compare two subβparts (upstream version or revision) by splitting via version_split_digits() and comparing items. Returns -1, 0, 1.@items = version_split_digits($version) β Splits a string into items of allβdigits or allβnonβdigits, e.g., β1.024~beta1+svn234β β (β1β, β.β, β024β, β~betaβ, β1β, β+svnβ, β234β).($ok, $msg) = version_check($version) / $ok = version_check($version) β Checks validity. Returns 1 in $ok if the version is valid, 0 otherwise; $msg contains the problem description if invalid.Remove deprecation warning from semantic change in 1.02.
Semantic change: bool evaluation semantics restored to their original behavior.
New argument: Accept an options argument in $v->as_string().
New method: $v->is_native().
Mark the module as public.
1.21.1 2025-09-09 Dpkg::Version(3perl)
Generated by phpman v4.9.25-3-gdbaf087 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-06 23:11 @216.73.217.93
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-pro / taotoken.net / www.chedong.com - original format