in reply to Re: Fast wordlist lookup for game
in thread Fast wordlist lookup for game

Thanks for the reply but I have to say that memory always seems to be an issue if one uses expensive methods and the script gets heavily used at all.
Thanks though,
jg

Replies are listed 'Best First'.
Re: Re: Re: Fast wordlist lookup for game
by sauoq (Abbot) on Oct 29, 2002 at 23:56 UTC

    Use a hash to minimize the search time. Keep the hash on disk to minimize the memory usage (and start-up time if this is a CGI app.) I.e. Use a DBM. For speed, you'll probably find BerkeleyDB is best.

    -j
    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Re: Re: Fast wordlist lookup for game
by agentv (Friar) on Oct 29, 2002 at 23:02 UTC
    ...oops, I guess I finished my post after you'd already seen a similar answer.

    You're right that it's expensive to keep the list in memory, but it will be the fastest, and we're not talking a lot of memory here (given a list with words on average the size of the words in the Unix dictionary).

    Reading things into the hash is not he most elegant solution, and someone will no doubt come along here in a moment with a suggestion for a module that does more closely what you desire, but I wouldn't discount the simplest approach, unless your program will have other memory intensive techniques that cannot be avoided.

    ...All the world looks like -well- all the world, when your hammer is Perl.
    ---v

      Thanks agentv,
      I will keep an open mind on this. I will be using this as the backend of a Flash game and since that will mean repeatedly incurring the memory penalty I doubt it will be the way I go. Guess it would have been much smarter of me to have said so in my original post, eh?
      Thanks for the replies!
      jg