On 8/21/07, Tony Heal <[EMAIL PROTECTED]> wrote:
> Here is a sample of the versions that I am using.
snip

Just to clarify, you have a version string with the following format:

{major}{custom tag}.{minor}-{build}

and you want the list sorted by major, then minor, then build.

#!/usr/bin/perl

use strict;
use warnings;

my @versions;
while (<DATA>) {
        chomp;
        die "invalid format" unless
                my ($major, $minor, $build) = /(\d+)(?:-.+)?\.(\d+)-(\d+)/;
        push @versions, [ $major, $minor, $build , $_];
}

print "$_->[-1]\n" for sort {
        $a->[0] <=> $b->[0] or
        $a->[1] <=> $b->[1] or
        $a->[2] <=> $b->[2]
} @versions;

__DATA__
16.1-17
16.1-22
16.1-23
16.1-39
16.3-1
16.3-6
16.3-7
16.3-8
16.3-15
16.5-1
16.5-2
16.5-10
16.5-13
15.3-12
15.2-108
14-special.1-2
14-special.1-8
14-special.1-15
14-special.2-40
14-special.2-41
14-special.3-4
14-special.3-7
14-special.3-12
15.2-110
15.2-111
15-special.1-52
15-special.1-53
15-special.1-54
16-special.4-9
16-special.4-10
16-special.5-1
16-special.5-2
16-special.6-6

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to