Excellent catch, and a great test case. My approach was wrong. In order to sort this in a DWIM-like way, this would probably work better:
my @old = ("10.5 AA", "100 NO");
my @new = map { join(' ',@$_) } sort {
($b->[0] <=> $a->[0]) || ($b->[1] cmp $a->[1])
} map { ($1,$2) if m/(.*?)\s(.*)/ } @old;
That's a bit cryptic. Basically, split each component of @old into number and string "columns", then use a two-criteria sort (sort on number, then string) and rejoin the "columns" into a string again.
<-radiant.matrix->
Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law
|