Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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?
[erix]: PostgreSQL 10 rc 1 is released

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-09-21 13:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (248 votes). Check out past polls.

    Notices?