Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to How can I sort my array numerically on part of the string?

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11124475]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found