diff options
author | jluehrs2 <jluehrs2@uiuc.edu> | 2008-02-02 20:28:41 -0500 |
---|---|---|
committer | jluehrs2 <jluehrs2@uiuc.edu> | 2008-02-02 20:28:41 -0500 |
commit | 43be917b6b4b33d17efacbbb1e53708e6413c176 (patch) | |
tree | 86ce8985cad4b84cb6618358e1b7a44dec6e0022 | |
parent | b53429c42da5f8845f4fae14b181ade862711a49 (diff) | |
download | games-word-43be917b6b4b33d17efacbbb1e53708e6413c176.tar.gz games-word-43be917b6b4b33d17efacbbb1e53708e6413c176.zip |
loop over all words, not all permutations to search for anagrams
-rw-r--r-- | lib/Games/Word/Wordlist.pm | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/Games/Word/Wordlist.pm b/lib/Games/Word/Wordlist.pm index 7dd5d28..5471d3e 100644 --- a/lib/Games/Word/Wordlist.pm +++ b/lib/Games/Word/Wordlist.pm @@ -2,7 +2,7 @@ package Games::Word::Wordlist; use strict; use warnings; -use Games::Word qw/all_permutations is_subpermutation/; +use Games::Word qw/is_permutation all_permutations is_subpermutation/; use List::MoreUtils qw/uniq/; =head1 NAME @@ -280,7 +280,11 @@ sub anagrams { my $self = shift; my $word = shift; - return uniq grep { $self->is_word($_) } all_permutations($word); + my @words = (); + $self->_each_word(sub { push @words, $_[0] + if is_permutation($word, $_[0]) }); + + return @words; } =item words_like REGEX |