NAME

Games::Word - utility functions for writing word games

VERSION

version 0.06

SYNOPSIS

    use Games::Word;
    print "permutation!\n" if is_permutation 'word', 'orwd';
    my $mm_solution = random_string_from "abcdefgh";
    my $mm_guess = <>;
    chomp $mm_guess;
    my $mm_correct_letters = shared_letters $mm_solution, $mm_guess;
    my $mm_correct_positions = shared_letters_by_position $mm_solution,
                                                          $mm_guess;

DESCRIPTION

Games::Word provides several utility functions for writing word games, such as manipulating permutations of strings, testing for similarity of strings, and finding strings from a given source of characters.

random_permutation STRING

Returns a string which is a random permutation of the letters in STRING.

is_permutation STRING1, STRING2

Returns true of STRING1 is a permutation of STRING2, and false otherwise.

all_permutations STRING

Returns a list containing all permutations of the characters in STRING.

shared_letters STRING1 STRING2

Returns a list of the characters that STRING1 and STRING2 have in common, ignoring their position in the string.

shared_letters_by_position STRING1 STRING2

In list context, returns a list that is the length of the larger of STRING1 and STRING2, which contains the character at that position in both strings if they are the same, and undef otherwise.

In scalar context, returns the number of characters that are the same in both value and position between STRING1 and STRING2.

random_string_from STRING LENGTH

Uses STRING as an alphabet to generate a random string of length LENGTH. Characters in STRING may be repeated.

is_substring SUBSTRING STRING

Returns true if SUBSTRING consists of only characters from STRING, in order. For example, 'word' is a substring of 'awobbrcd', but not of 'dcrbbowa' or 'awbbrcd'.

all_substrings STRING

Returns a list of all substrings (see is_substring) of STRING.

is_subpermutation SUBSTRING STRING

Returns true if SUBSTRING is a subpermutation (like is_substring, but without caring about order) of STRING, and false otherwise.

all_subpermutations STRING

Like all_substrings, except using is_subpermutation instead.

BUGS

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.

SEE ALSO

Games::Word::Wordlist

SUPPORT

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

    perldoc Games::Word

You can also look for information at:

AUTHOR

Jesse Luehrs <doy at tozt dot net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Jesse Luehrs.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.