Games::Word::Wordlist - manages a list of words


Games-Word documentation  | view source Contained in the Games-Word distribution.

Index


NAME

Top

Games::Word::Wordlist - manages a list of words

VERSION

Top

version 0.05

SYNOPSIS

Top

    use Games::Word::Wordlist;
    my $wl = Games::Word::Wordlist->new('/usr/share/dict/words');
    my $word = $wl->random_word;
    print "we have a word" if $wl->is_word($word);

DESCRIPTION

Top

Games::Word::Wordlist manages a list of words, either from a wordlist file on your computer or from a list of words you specify. You can use it to query things about the list, such as whether a given string is a word, or how many words are in the list, and you can also get words from the list, either randomly or by regex.

CONSTRUCTOR

Top

new <FILENAME|ARRAYREF> PARAMHASH

The constructor initializes the word list with words, either from a file or from an arrayref, given as the first argument. The remaining arguments are a paramhash which recognizes these options:

cache

Whether or not we want to keep an in memory cache of the words in the word list. Defaults to true, since this is what we want in almost all cases, as it speeds up lookups by several orders of magnitude. Can be set to false if either memory is a significant issue (word lists can be several megabytes in size) or if the word list is expected to change frequently during the running of the program.

METHODS

Top

add_words <FILENAME|ARRAYREF>

Add words to the word list. Only works if the word list has been cached.

Takes either a reference to an array containing the new words, or the name of a file to read in the words from. Ignores any words already in the word list.

remove_words LIST

Removes words in LIST from the word list. Only works if the word list is cached.

words

Returns the number of words in the word list.

random_word [LENGTH]

Returns a random word from the word list, optionally of length LENGTH.

is_word STRING

Returns true if STRING is found in the word list, and false otherwise.

each_word CODE

Call CODE for each word in the word list. The current word will be passed into CODE as its only argument.

anagrams STRING

Returns a list of all permutations of STRING that are found in the word list.

words_like REGEX

Returns a list containing all words in the word list which match REGEX.

subwords_of STRING

Returns a list of words from the word list which can be made using the letters in STRING.

SEE ALSO

Top

Games::Word

AUTHOR

Top

Jesse Luehrs, <doy at tozt dot net>

BUGS

Top

No known bugs.

Please report any bugs through RT: email bug-games-word at rt.cpan.org, or browse http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Word.

SUPPORT

Top

You can find this documentation for this module with the perldoc command.

    perldoc Games::Word::Wordlist

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Games-Word

* CPAN Ratings

http://cpanratings.perl.org/d/Games-Word

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-Word

* Search CPAN

http://search.cpan.org/dist/Games-Word

COPYRIGHT AND LICENSE

Top


Games-Word documentation  | view source Contained in the Games-Word distribution.