in reply to sorting by numbers then alphabetically

Another way, using decorate-undecorate, and including the latest requirement for case-insensitive sorting (but see also Sort::Maker):

>perl -wMstrict -le "my $ar = [ qw(X1 Mt10 mT2 y20 Y1 Y10 mt20 x20 X10) ]; ;; my @sorted = map { undecorate($_) } sort map { print qq{'$_'}; $_ } map { decorate($_) } @$ar ; ;; print qq{'$_'} for @sorted; ;; use constant WIDTH => 10; use constant SEP => ':'; ;; sub decorate { my ($num) = $_[0] =~ m{ (\d+) }xms; my ($alpha) = $_[0] =~ m{ ([[:alpha:]]+) }xms; return sprintf '%0*d%s%s%s', WIDTH, $num, lc($alpha), SEP, $_[0]; } ;; sub undecorate { return substr $_[0], 1 + index $_[0], SEP; } " '0000000001x:X1' '0000000010mt:Mt10' '0000000002mt:mT2' '0000000020y:y20' '0000000001y:Y1' '0000000010y:Y10' '0000000020mt:mt20' '0000000020x:x20' '0000000010x:X10' 'X1' 'Y1' 'mT2' 'Mt10' 'X10' 'Y10' 'mt20' 'x20' 'y20'

Note: The  map { print qq{'$_'};  $_ } step above is just to show the effect of decoration.

Also: The two regexes could be combined into one in the  decorate() function.

Update: See also Re: Help Manipulating Sort with Subroutines for another variation of this 'pattern'.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.