From 6a7b61d22dead93a18b56fc409a9b4be7034563a Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Thu, 31 Jan 2008 20:02:34 -0500 Subject: add an anagrams() function to get anagrams of a word --- lib/Games/Word/Wordlist.pm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Games/Word/Wordlist.pm b/lib/Games/Word/Wordlist.pm index 399aff4..f7f9716 100644 --- a/lib/Games/Word/Wordlist.pm +++ b/lib/Games/Word/Wordlist.pm @@ -2,6 +2,8 @@ package Games::Word::Wordlist; use strict; use warnings; +use Games::Word qw/all_permutations/; +use List::MoreUtils qw/uniq/; sub new { my $class = shift; @@ -105,6 +107,13 @@ sub _each_word { return $self->_each_word_nocache(@_); } +sub anagrams { + my $self = shift; + my $word = shift; + + return uniq grep { $self->is_word($_) } all_permutations($word); +} + =head1 NAME Games::Word::Wordlist - ??? -- cgit v1.2.3-54-g00ecf