in reply to How to perform different sorts on multiple sections of items in the same array
Rather than complicated sorting routines, perhaps it would be preferable to set up a couple of "flags" depending on what type the string is and, consequently, what character to sort on then pack them along with the original string to do a GRT sort. This will not be stable for the last two categories if the strings share the same sorting character, at which point they will be sorted in ascending alpha.
use strict; use warnings; use 5.014; my @strings = qw{ cabin prawn pail error reptile engine copy echo soap eskimo carpet emblem skunk }; say for map { substr $_, 8 } sort map { my( $type, $ord ); if ( m{r} ) { $type = 0; $ord = 0; } elsif ( m{^e} ) { $type = 1; $ord = ord substr $_, 2, 1; } else { $type = 2; $ord = 255 - ord substr $_, -1, 1; } pack q{NNa*}, $type, $ord, $_; } @strings;
The output.
carpet error prawn reptile emblem engine echo eskimo copy soap cabin pail skunk
I hope this is of interest.
Update: Corrected statement re. stable sorting, s/first/last/
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to perform different sorts on multiple sections of items in the same array
by BrowserUk (Patriarch) on Dec 30, 2014 at 02:00 UTC | |
by johngg (Canon) on Dec 30, 2014 at 12:28 UTC | |
by BrowserUk (Patriarch) on Dec 30, 2014 at 12:40 UTC | |
|
Re^2: How to perform different sorts on multiple sections of items in the same array
by johngg (Canon) on Dec 31, 2014 at 00:40 UTC |