JungleBoy has asked for the wisdom of the Perl Monks concerning the following question:
Here's what I was able to come up with. It'll correctly find anagrams, but it will also come up with a lot of false positives. It'll match any words of the right length, and with the right letters, but the number of letters won't be right. For example, it'll incorrectly match abcde to aaaaa.
Anyone got a simple and correct solution?open (INFILE, '<wordlist'); my $word = lc($ARGV[0]); my $size = length($word); while ($foo = <INFILE>) { if (lc($foo) =~ /^[$word]{$size}$/o) { print "Match: " . $foo . "\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Anagram matching
by Fastolfe (Vicar) on Nov 06, 2001 at 03:29 UTC | |
|
Re: Anagram matching
by Masem (Monsignor) on Nov 06, 2001 at 03:29 UTC | |
|
Re: Anagram matching
by merlyn (Sage) on Nov 06, 2001 at 03:19 UTC | |
by JungleBoy (Scribe) on Nov 06, 2001 at 03:26 UTC | |
by merlyn (Sage) on Nov 06, 2001 at 03:57 UTC |