summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Rollyson <srollyson@cpan.org>2012-07-04 21:57:31 -0400
committerStephen Rollyson <srollyson@cpan.org>2012-07-04 21:57:31 -0400
commit57acbbb1df995469780164a5b7a7148753d6c4d0 (patch)
tree388c031da05d9c6926925ac8978f34de1427dffa
parentd9e06b0fde102ee76266070d49c4f84916f7896a (diff)
downloadgames-word-57acbbb1df995469780164a5b7a7148753d6c4d0.tar.gz
games-word-57acbbb1df995469780164a5b7a7148753d6c4d0.zip
Optimized Wordlist's anagrams and subwords_of.
-rw-r--r--lib/Games/Word/Wordlist.pm14
1 files changed, 3 insertions, 11 deletions
diff --git a/lib/Games/Word/Wordlist.pm b/lib/Games/Word/Wordlist.pm
index 98d1e4a..30d2be4 100644
--- a/lib/Games/Word/Wordlist.pm
+++ b/lib/Games/Word/Wordlist.pm
@@ -1,7 +1,7 @@
package Games::Word::Wordlist;
use strict;
use warnings;
-use Games::Word qw/is_permutation all_permutations is_subpermutation/;
+use Games::Word qw/all_permutations all_subpermutations/;
use List::MoreUtils qw/uniq/;
=head1 NAME
@@ -278,11 +278,7 @@ sub anagrams {
my $self = shift;
my $word = shift;
- my @words = ();
- $self->each_word(sub { push @words, $_[0]
- if is_permutation($word, $_[0]) });
-
- return @words;
+ return grep {$self->is_word($_)} all_permutations($word);
}
=item words_like REGEX
@@ -312,11 +308,7 @@ sub subwords_of {
my $self = shift;
my $string = shift;
- my @words = ();
- $self->each_word(sub { push @words, $_[0]
- if is_subpermutation($_[0], $string)});
-
- return @words;
+ return grep {$self->is_word($_)} all_subpermutations($string);
}
=back