in reply to The longest word ....
I think you want to do the hash the other way around. I.e. make it a hash of lengths and push each word onto an anonymous array of words of than length:
Notes: If you do a print Dumper (\%W); before the return you will see the hash that has been constructed.sub longest_words { my %W; push (@{$W{length($_)}}, $_) for (split /\s+/, join ' ', @_); return @{$W{ (sort{$b <=>$a} keys %W)[0]} }; }
Dingus
|
---|