in reply to Re: Numeric Sort for Stringified Value (How to Avoid Warning)
in thread Numeric Sort for Stringified Value (How to Avoid Warning)
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.
|
|---|