in reply to Helping with sorting

How about a Schwartzian Transform?
use strict; use warnings; my @array = qw(2aa 2ba 12kf 9cn 9vn 21sg); my @sorted = map { join('',@$_) } sort { $b->[0] <=> $a->[0] or $a->[1] cmp $b->[1] } map { /(\d+)(\w+)/;[$1,$2] } @array ; print "$_\n" foreach @sorted; __END__ 21sg 12kf 9cn 9vn 2aa 2ba
Update: be sure and read japhy's Resorting to Sorting. Especially the part about the Guttman Rosler transforms. (i'll leave that implementation of this particular problem as an exercise for another monk ;))

Update2: just noticed that the map after the sort could be written more consisely as:

map { [/(\d+)(\w+)/] } @array
Update3: fixed typo (s/b->\[1/a->[1/) ... thanks Enlil :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: Helping with sorting
by kiat (Vicar) on Apr 02, 2003 at 05:37 UTC
    Thanks to all! I've not only solved the problem I was facing but I'm also learning a lot =)
Re: (jeffa) Re: Helping with sorting
by aquarium (Curate) on Apr 03, 2003 at 12:36 UTC
    I can't make out where to apply your update3 in your code...if it at all applies to the problem produced in the output "9cn", should be "9nc". Update4?? :) Chris