ChOas has asked for the wisdom of the Perl Monks concerning the following question:
Now the output is really what I would like it to be....#!/usr/bin/perl -w use strict; sub ByVersion; my @VersionList=("1.1","1.1.1","2.0","1.2_patch3","33.0","1.1.1.1","1. +a.1","1.b.1","1.b.1.a","1.b.1.b","1.33.0","1.0.a","1.0.b","33.1","6.6 +.6","10.0","9.0","3.1.4","3.1.12"); chomp (@VersionList); my @Sorted=sort ByVersion @VersionList; print "Sorted to: @Sorted\n"; sub ByVersion { my @First=split /\./,$a; my @Second=split /\./,$b; my $Nr=($#First>$#Second)?$#Second:$#First; foreach(0..$Nr) { next if ($First[$_] eq $Second[$_]); return ("$First[$_]$Second[$_]"=~/^\d$/o)?($First[$_] <=> $Second[$_ +]):($First[$_] cmp $Second[$_]); } return ($#First>$#Second)?1:-1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sort ByVersion
by japhy (Canon) on Nov 02, 2000 at 18:27 UTC | |
by ChOas (Curate) on Nov 02, 2000 at 21:14 UTC | |
|
(tye)Re: Sort ByVersion
by tye (Sage) on Nov 02, 2000 at 21:05 UTC |