in reply to Sort problems
You could also try a Guttman Rosler transform. This melds the fields to sort and the whole item into a single string that can be sorted lexically. The original item can then be pulled from the sorted string afterwards. pack or sprintf are often used to construct the string. Care has to be taken to make sure the fields pack to a consistent length across all of the list to be sorted!
use strict; use warnings; my @list = qw{ a1_2 a1_1 a10_10 a2_10 a2_1 a2_2 a10_1 a10_2 a1_10 }; my @sorted = map { substr $_, 8 } sort map { pack q{NNa*}, m{(\d+)_(\d+)}, $_ } @list; print qq{$_\n} for @sorted;
The output.
a1_1 a1_2 a1_10 a2_1 a2_2 a2_10 a10_1 a10_2 a10_10
I hope this is of interest.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort problems
by AnomalousMonk (Archbishop) on Dec 03, 2008 at 03:08 UTC | |
by johngg (Canon) on Dec 03, 2008 at 10:22 UTC | |
by monarch (Priest) on Dec 04, 2008 at 03:38 UTC |