Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: The longest word ....

by BrowserUk (Pope)
on Nov 12, 2002 at 10:01 UTC ( #212235=note: print w/replies, xml ) Need Help??


in reply to Re: The longest word ....
in thread The longest word ....

Caveats noted, the problem wasn't "the longest word" but the longest words, which is either

  • Two passes.

    1 to get the length, one extract the words of that length.

  • Requires building a hash (or similar) to record the lengths and the words.

The former would work on a list greater than memory, the latter is likely to fail before the sort.

Anyone who "throws a wordlist" at an algorithm without understanding its limitations, gets what they deserve.

In the context of the requested solution: A shorter way of finding the longest words in a supplied string (already memory bound) using sort was just a quick option. I didn't read the question as requiring a failsafe nor scalable solution. Did you?

After all

print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

is probably not the most efficient way of printing "just another bofh" either.


Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

Replies are listed 'Best First'.
Re: Re: Re: The longest word ....
by Anarion (Hermit) on Nov 12, 2002 at 12:54 UTC
    Another point of view without using sort:

    sub lword{ push(@{$a[length]},$_)for(pop)=~/\b\w+/g;@{$a[-1]} }

    Or clean the array every iteration too:
    sub lword2{ for((pop)=~/\b\w+/g){push(@{$a[length]},$_);@b[0..-2]=''}@{$a[-1]} }

    Update:(Changed "while" with "for" after testing)

    $anarion=\$anarion;

    s==q^QBY_^=,$_^=$[x7,print

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://212235]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2020-09-21 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (126 votes). Check out past polls.

    Notices?