laziness, impatience, and hubris | |
PerlMonks |
Re: How can I sort my array numerically on part of the string?by GrandFather (Saint) |
on Dec 01, 2020 at 20:38 UTC ( [id://11124475]=note: print w/replies, xml ) | Need Help?? |
The "how" has been sorted by others, but no explicit mention of "why". Perl's sort comes in a number of different forms. The short form of sort is essentially the same as sort {$a cpm $b} .... cmp (see perlop for cmp and <=>) compares strings so things that look like numbers are sorted like strings. To sort numerically you need the numeric comparison operator <=>. Sort then looks like sort {$a <=> $b} ....
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
In Section
Seekers of Perl Wisdom
|
|