in reply to The longest word ....

Here is one way, and the real part only takes one line.
use strict; my @words = ("one", "two", "three", "four", "sumofallnumbers", "five", + "six", "seven", "eight"); my @sorted_words = sort {length($b) <=> length($a)} @words; print "the longest word is: $sorted_words[0]";

Replies are listed 'Best First'.
Re: Re: The longest word ....
by pg (Canon) on Nov 12, 2002 at 04:30 UTC
    There could be more than one longest words having the same length, you probably want all of them:
    use strict; my @words = ("one", "two", "123456789012345", "three", "four", "sumofa +llnumbers", "five", "six", "seven", "eight"); my @sorted_words = sort {length($b) <=> length($a)} @words;

    my @longest_words = grep (/.{$#sorted_words}/, @words);
    print join(",", @longest_words);