1Versions(3)           User Contributed Perl Documentation          Versions(3)
2
3
4

NAME

6       Sort::Versions - a perl 5 module for sorting of revision-like numbers
7

SYNOPSIS

9               use Sort::Versions;
10               @l = sort { versioncmp($a, $b) } qw( 1.2 1.2.0 1.2a.0 1.2.a 1.a 02.a );
11
12               ...
13
14               use Sort::Versions;
15               print 'lower' if versioncmp('1.2', '1.2a') == -1;
16
17               ...
18
19               use Sort::Versions;
20               %h = (1 => 'd', 2 => 'c', 3 => 'b', 4 => 'a');
21               @h = sort { versioncmp($h{$a}, $h{$b}) } keys %h;
22

DESCRIPTION

24       Sort::Versions allows easy sorting of mixed non-numeric and numeric
25       strings, like the 'version numbers' that many shared library systems
26       and revision control packages use. This is quite useful if you are
27       trying to deal with shared libraries. It can also be applied to
28       applications that intersperse variable-width numeric fields within
29       text. Other applications can undoubtedly be found.
30
31       For an explanation of the algorithm, it's simplest to look at these
32       examples:
33
34         1.1   <  1.2
35         1.1a  <  1.2
36         1.1   <  1.1.1
37         1.1   <  1.1a
38         1.1.a <  1.1a
39         1     <  a
40         a     <  b
41         1     <  2
42         1.1-3 <  1.1-4
43         1.1-5 <  1.1.6
44
45       More precisely (but less comprehensibly), the two strings are treated
46       as subunits delimited by periods or hyphens. Each subunit can contain
47       any number of groups of digits or non-digits. If digit groups are being
48       compared on both sides, a numeric comparison is used, otherwise a ASCII
49       ordering is used. A group or subgroup with more units will win if all
50       comparisons are equal.  A period binds digit groups together more
51       tightly than a hyphen.
52
53       Some packages use a different style of version numbering: a simple real
54       number written as a decimal. Sort::Versions has limited support for
55       this style: when comparing two subunits which are both digit groups, if
56       either subunit has a leading zero, then both are treated like digits
57       after a decimal point. So for example:
58
59         0002  <  1
60         1.06  <  1.5
61
62       This won't always work, because there won't always be a leading zero in
63       real-number style version numbers. There is no way for Sort::Versions
64       to know which style was intended. But a lot of the time it will do the
65       right thing. If you are making up version numbers, the style with
66       (possibly) more than one dot is the style to use.
67

USAGE

69       The function "versioncmp()" takes two arguments and compares them like
70       "cmp".  With perl 5.6 or later, you can also use this function directly
71       in sorting:
72
73           @l = sort versioncmp qw(1.1 1.2 1.0.3);
74
75       The function "versions()" can be used directly as a sort function even
76       on perl 5.005 and earlier, but its use is deprecated.
77

AUTHOR

79       Ed Avis <ed@membled.com> and Matt Johnson <mwj99@doc.ic.ac.uk> for
80       recent releases; the original author is Kenneth J. Albanowski
81       <kjahds@kjahds.com>.  Thanks to Hack Kampbjorn and Slaven Rezic for
82       patches and bug reports.
83
84       Copyright (c) 1996, Kenneth J. Albanowski. All rights reserved.  This
85       program is free software; you can redistribute it and/or modify it
86       under the same terms as Perl itself.
87

POD ERRORS

89       Hey! The above document had some coding errors, which are explained
90       below:
91
92       Around line 141:
93           Non-ASCII character seen before =encoding in 'Kampbjorn'. Assuming
94           UTF-8
95
96
97
98perl v5.16.3                      2003-08-24                       Versions(3)
Impressum