# info > Dpkg::Version

---
type: CommandReference
command: Dpkg::Version
mode: perldoc
section: 3perl
source: perldoc
---

## Quick Reference
- `my $v = Dpkg::Version->new('1:2.0-1');` — create a version object
- `$v->is_valid()` — returns true if version is valid
- `$v1 <=> $v2` — three-way comparison (spaceship operator)
- `version_compare('1.0', '2.0')` — returns -1 (1.0 earlier)
- `version_compare_relation($a, REL_GT, $b)` — true if $a > $b
- `$v->as_string(omit_epoch => 1)` — string with epoch omitted
- `$v->epoch()` — get the epoch part
- `version_check($ver)` — returns validity and optional error message

## Name
Dpkg::Version — handling and comparing dpkg-style version numbers

## Synopsis
perl
use Dpkg::Version;

my $v1 = Dpkg::Version->new('1.2.3~beta1+dfsg-1');
my $v2 = Dpkg::Version->new('2:1.2.3-1');

if ($v1 < $v2) { ... }

my $cmp = version_compare($v1->as_string, '1.2.3');
## Methods
- `Dpkg::Version->new($version, %opts)` — Constructor. Returns undef if `check => 1` and version invalid. The object can later be checked with `$v->is_valid()`.
- `$v` in boolean context — Returns true if valid (`$v->is_valid()`), otherwise false. Prior to dpkg 1.19.1 the overload stringified, causing “0” to be false; fix by quiescing warning (see docs).
- `$v->is_valid()` — Returns true for a valid dpkg version, false otherwise.
- `$v->epoch()` — Returns the epoch part.
- `$v->version()` — Returns the upstream version part.
- `$v->revision()` — Returns the Debian revision part.
- `$v->is_native()` — Returns true if the version is native (no revision).
- `$v1 <=> $v2`, `$v1 < $v2`, etc. — Overloaded comparison operators. One operand must be a `Dpkg::Version` object; the other can be a string that looks like a version.
- `$v->as_string(%options)` — String representation. Options: `omit_epoch` (default 0) and `omit_revision` (default 0). Stringification `"$v"` is equivalent.

## Functions
All functions are exported by default.

- `version_compare($a, $b)` — Returns -1 if $a < $b, 0 if equal, 1 if $a > $b. Dies if either argument is not a valid version.
- `version_compare_relation($a, $rel, $b)` — Tests a relation: uses constants `REL_GT`, `REL_GE`, `REL_EQ`, `REL_LE`, `REL_LT`. Returns 1 if the relation holds, 0 otherwise.
- `version_normalize_relation($rel_string)` — Converts strings like `'>>'`, `'='`, `'lt'` into the corresponding constant.
- `version_compare_string($a, $b)` — Low-level string comparison for non‑numerical parts. `~` sorts lowest; digits sort before non‑digits; alphabetic before other non‑digits; ASCII order within each group.
- `version_compare_part($a, $b)` — Compares two version sub‑parts (e.g. upstream or revision) by splitting into digit/non‑digit runs and comparing each.
- `version_split_digits($version)` — Splits version string into alternating digit and non‑digit items.
- `version_check($version)` — In scalar context returns 1 if valid, 0 otherwise. In list context returns `($ok, $msg)`, where `$msg` describes the problem when invalid.

## See Also
- [dpkg(1)](http://localhost/phpMan.php/man/dpkg/1/markdown)
- [deb-version(7)](http://localhost/phpMan.php/man/deb-version/7/markdown)

## Exit Codes
Not applicable.