From 43be917b6b4b33d17efacbbb1e53708e6413c176 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Sat, 2 Feb 2008 20:28:41 -0500 Subject: loop over all words, not all permutations to search for anagrams --- lib/Games/Word/Wordlist.pm | 8 ++++++-- 1 file 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 -- cgit v1.2.3