Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Sort by string length

by Enlil (Parson)
on Sep 03, 2004 at 21:59 UTC ( #388426=note: print w/replies, xml ) Need Help??


in reply to Sort by string length

my @sorted_by_length = sort { length($a) <=> length($b) } @elements;
or if you feel so inclined to do a schwartzian type transform (used when an expensive function is used to evaluate order):
my @sorted_by_length = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, length($_) ] } @elements
HTH

-enlil

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://388426]
help
Chatterbox?
[choroba]: TITS = Try It To See :-)

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2017-01-17 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (153 votes). Check out past polls.