in reply to How to sorting
#!/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
|
|---|