Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Sorting Numbers & Text

by kcott (Archbishop)
on Jul 13, 2012 at 06:18 UTC ( [id://981564]=note: print w/replies, xml ) Need Help??


in reply to Sorting Numbers & Text

This gives the output you wanted:

$ perl -Mstrict -Mwarnings -MScalar::Util=looks_like_number -E ' my @values = qw{041351920234 Rabbit 0343120 041271024500 0430870 Apple + 041460301399}; say for sort { looks_like_number($a) && looks_like_number($b) ? $a <=> $b : looks_like_number($a) ? 1 : looks_like_number($b) ? -1 : $a cmp $b } @values; ' Apple Rabbit 0343120 0430870 041271024500 041351920234 041460301399

-- Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-20 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found