Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Module Submission for CPAN

by dchetlin (Friar)
on Dec 13, 2000 at 01:57 UTC ( #46334=note: print w/ replies, xml ) Need Help??


in reply to Module Submission for CPAN

This is good code and will fill a hole on the CPAN. I was looking for something similar several months ago and came up with nothing.

I have a couple of suggestions that I hope will be helpful.

  • Firstly, I believe there is an alternative data structure that will really speed up your lookups. Here is my suggested algorithm for building it:

    s/\W//g, push @{$dict{join "", sort split //, lc}}, $_ for <DICT>;

    In other words, sort each word and store it in its canonical form in the lookup table, so all anagrams are stored together. Then, when you want to check for anagrams of a word, you just go straight to its canonical key in the hash.

    This might make your starts_word slower/less clear, but I'm not sure. Of course, starts_word won't be necessary for anagram lookups anymore, but it would be a useful standalone function.

  • You'll probably want to do something more robust than assume /usr/dict/words. There are MakeMaker settings to play around with, but I imagine it will be a pain. Somehow, though you'll have to at least make a way for the user to specify where their dictionary is.

  • You probably shouldn't use a global for the lookup table.

  • You don't have to put that initialization code in a BEGIN block.

  • $VERSION is almost always in all caps.

  • Am I missing something, or does walk_dict() not seem to exist?

-dlc


Comment on Re: Module Submission for CPAN
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-09-02 13:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (22 votes), past polls