in reply to How to sorting

Assuming that you want the letter part sorted before the number part and expanding the requirement slightly to cope with invalid IDs, you could use a kind of Schwartzian Transform. In addition to the fields you want to sort on, I include a field for validity. You can then either exclude the invalid IDs or sort them to the end of the array.

#!/usr/bin/perl -l # use strict; use warnings; my @articleIDs = qw{ b1 27 b2 b3 a100 ab35 b17 a5 a8 a10 a11 badID }; my @sortedGoodIDs = map { $_->[ 0 ] } sort { $a->[ 2 ] cmp $b->[ 2 ] || $a->[ 3 ] <=> $b->[ 3 ] } grep { $_->[ 1 ] } map { [ $_, m{^([a-z]+)(\d+)$} ? 1 : 0, $1, $2 ] } @articleIDs; print for @sortedGoodIDs, q{-} x 15; my @sortedAllIDs = map { $_->[ 0 ] } sort { $b->[ 1 ] <=> $a->[ 1 ] || $a->[ 2 ] cmp $b->[ 2 ] || $a->[ 3 ] <=> $b->[ 3 ] } map { [ $_, m{^([a-z]+)(\d+)$} ? ( 1, $1, $2 ) : ( 0, q{}, 0 ) ] } @articleIDs; print for @sortedAllIDs, q{-} x 15;

The output.

a5 a8 a10 a11 a100 ab35 b1 b2 b3 b17 --------------- a5 a8 a10 a11 a100 ab35 b1 b2 b3 b17 27 badID ---------------

I hope this is of interest.

Cheers,

JohnGG