Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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


Comment on Re: Sort by string length
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2015-07-07 07:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls