in reply to Data with Letter(s) & Number sort query
What you want is a natural sort then. The usual approach is to create for each element to be sorted a string that sorts lexically but from which you can find the original string again. For example, you could build your string by having the padded string, a \0 and then the original string:
my @elements = map { join "\0", padded($_), $_ } @original; @elements = sort { $a cmp $b } @elements; my @sorted = map { ( split /\0/, $_ )[1] } @elements;
You can even chain it all together like the following:
my @elements = map { ( split /\0/, $_ )[1] } sort { $a cmp $b } map { join "\0", padded($_), $_ } @original;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Data with Letter(s) & Number sort query
by AnomalousMonk (Archbishop) on Nov 19, 2016 at 18:37 UTC | |
|
Re^2: Data with Letter(s) & Number sort query
by hippo (Archbishop) on Nov 19, 2016 at 10:08 UTC | |
by Corion (Patriarch) on Nov 19, 2016 at 11:02 UTC | |
by merrymonk (Hermit) on Nov 19, 2016 at 11:42 UTC | |
by Corion (Patriarch) on Nov 19, 2016 at 12:56 UTC | |
by Laurent_R (Canon) on Nov 19, 2016 at 10:13 UTC |