Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Answer: How do I do a natural sort on an array?

( #68189=categorized answer: print w/ replies, xml ) Need Help??

Q&A > sorting > How do I do a natural sort on an array? - Answer contributed by indigo

@a = sort @b;

will sort lexigraphically.

@a = sort { $a <=> $b } @b;

will sort numerically.

@a = sort &naturally @b;

will sort "naturally", where naturally() is a compare routine of your own devising.

perldoc -f sort for more info.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2016-08-26 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (366 votes). Check out past polls.