Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 cooling their heels in the Monastery: (10)
As of 2014-12-25 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls