Jul 28, 2006 #1 danny2785 Programmer Jun 26, 2006 16 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
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
Jul 28, 2006 #2 ishnid Programmer Aug 29, 2003 1,422 IE Not if the list isn't ordered by string length. Upvote 0 Downvote
Jul 31, 2006 1 #3 TrojanWarBlade Programmer Apr 13, 2005 1,783 GB This is cheating a little but it should do the trick: Code: my $longest = (sort {length($b)<=>length($a)} @strings)[0]; Trojan. Upvote 0 Downvote
This is cheating a little but it should do the trick: Code: my $longest = (sort {length($b)<=>length($a)} @strings)[0]; Trojan.