in reply to Re: The longest word ....
in thread The longest word ....
Of course using sort just makes it too easy. :-)
sub longest_words { my @W = sort { length($b) <=> length($a) } $_[0] =~ /\b(\w+)\b/g; grep length == length($W[0]), @W; }
As long as you do it right, that is. You'll need to use <=> in your sort. Just testing for 'greater than' isn't sufficient.
Update: A little golfing gets the sub down to 79 characters:
sub longest_words { my@W=sort{length($b)<=>length($a)}$_[0]=~/(\w+)/g;grep length==length( +$W[0]),@W }
-sauoq "My two cents aren't worth a dime.";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: The longest word ....
by Juerd (Abbot) on Nov 13, 2002 at 00:50 UTC | |
Re: Re: Re: The longest word ....
by AltBlue (Chaplain) on Nov 12, 2002 at 14:36 UTC | |
by sauoq (Abbot) on Nov 12, 2002 at 20:11 UTC |