Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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

by indigo (Scribe)
on Mar 30, 2001 at 00:53 UTC ( #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?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2017-04-30 10:07 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (535 votes). Check out past polls.