Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding the string with the longest length 1

Status
Not open for further replies.

danny2785

Programmer
Jun 26, 2006
16
0
0
US
If I have a list of strings, is there a way to find the string with the longest length without iterating through each component of the list? Thanks
 
Not if the list isn't ordered by string length.
 
This is cheating a little but it should do the trick:
Code:
my $longest = (sort {length($b)<=>length($a)} @strings)[0];


Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top