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
In reply to Re: How to perform different sorts on multiple sections of items in the same array
by johngg
in thread How to perform different sorts on multiple sections of items in the same array
by estreb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |