in reply to Re: Sorting on Section Numbers
in thread Sorting on Section Numbers
my @sects= qw( 1 2 2.2 2.13 2.1.7 3.4a 10.1 10.10 10.1a 1a.2 ); my %sects; for ( @sects ) { ( my $key = $_ ) =~ s/(\d+)/substr("0000$1",-4)/ge; $sects{$key} = $_; } print "@sects{sort keys %sects}\n";
Parameterizing on $maxdigs is left an an excercise for the acolyte. :-) (And extra credit if you knew that you could interpolate a hash slice.)
If we simplify the problem space by eliminating the alphanumerics, things get even neater--we don't even need a hash any more:
my @sorted = map { join '.', unpack 'N*', $_ } sort map { pack 'N*', split /\./ } @unsorted;
-- Chip Salzenberg, Free-Floating Agent of Chaos
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: RE: Re: Sorting on Section Numbers
by tye (Sage) on Jul 28, 2000 at 17:15 UTC | |
by chip (Curate) on Jul 28, 2000 at 22:34 UTC | |
by tye (Sage) on Jul 28, 2000 at 23:32 UTC | |
RE: RE: Re: Sorting on Section Numbers
by jimt (Chaplain) on Jul 28, 2000 at 18:08 UTC | |
by chip (Curate) on Jul 28, 2000 at 22:40 UTC | |
by DrManhattan (Chaplain) on Jul 28, 2000 at 18:37 UTC | |
by turnstep (Parson) on Jul 28, 2000 at 21:27 UTC |