#myan.pl #short for "my anagram" # #usage: myan.pl (word) # #this finds all possible anagrams of a word or sequence of letters, without having to rely on wordsmith.org/anagram. I've drained enough server time from them! use strict; use warnings; my @wordAry = (); my $anno = "c:/writing/dict/anagram-notes.txt"; my $anaHtm = "c:/writing/dict/anagram-htm.htm"; use Time::HiRes qw(time); use POSIX qw(strftime); # options my $toFile = 1; my $checkAfter = 1; my $checkNames = 1; my $htmOut = 1; #global initializations my @isWord; my $myBase = ""; my $cmdToAn = ""; my $minWords = 2; my $maxWords = 2; my $maxAn = 1000; my $count = 0; my $printTimer = 1; my $hashy; my $calls; my $curMax; while ( $count <= $#ARGV ) { $a = $ARGV[$count]; $b = $ARGV[ $count + 1 ]; for ($a) { /^-?a$/ && do { `$anno`; exit; }; /^-?t$/ && do { noteCheck(); exit; }; /^-?ma$/ && do { $maxAn = $b; $count += 2; next; }; /^-?nn$/ && do { $checkNames = 0; $count++; next; }; /^-?cn$/ && do { $checkNames = 1; $count++; next; }; /^-?nc$/ && do { $checkAfter = 0; $count++; next; }; /^-?c$/ && do { $checkAfter = 1; $count++; next; }; /^-?np$/ && do { $printTimer = 0; $count++; next; }; /^-?p$/ && do { $printTimer = 1; $count++; next; }; /^-?f$/ && do { $toFile = 1; $count++; next; }; /^-?nf$/ && do { $toFile = 1; $count++; next; }; /^-?h$/ && do { $htmOut = 1; $count++; next; }; /^-?r$/ && do { my @mma = split( /,/, $b ); $minWords = $mma[0]; $maxWords = $mma[1]; $count++; next; }; /^-?m[0-9]$/ && do { $maxWords = $a; $maxWords =~ s/^-?m//; $count++; next; }; /^-?[0-9]$/ && do { $maxWords = $a; $maxWords =~ s/^-?//; $count++; next; }; /^-?m$/ && do { $maxWords = $b; $count += 2; next; }; /^-?mm$/ && do { $minWords = $maxWords = $b; $count += 2; next; }; /^[a-z]/i && do { if ($cmdToAn) { die("2 possible words, bailing.\n"); } else { $cmdToAn = lc($a); $count++; next; } }; usage(); } } if ( !$cmdToAn ) { die("I need a word to anagram."); } if ( ( length($cmdToAn) > 16 ) && ( $cmdToAn !~ /,/ ) ) { die("16 chars or fewer please."); } if ( $cmdToAn =~ /[^,a-z=\+]/i ) { print "Wiping out non-letter characters.\n"; $cmdToAn =~ s/[^,a-z]//gi; } $cmdToAn = lc($cmdToAn); if ( $cmdToAn !~ /,/ ) { $myBase = $cmdToAn; @wordAry = ($myBase); } else { @wordAry = split( /,/, $cmdToAn ); } my $lastOne; for my $inList (@wordAry) { $myBase = $inList; if ( $inList =~ /=/ ) { $myBase =~ s/=//g; $inList =~ s/=//g; print "= indicates plurals, trying both.\n"; anfind($myBase); $myBase = "s$inList"; anfind( $myBase . "s" ); } if ( $inList =~ /\+/ ) { $myBase = $inList; $myBase =~ s/\+/$lastOne/g; print "Tacking on $inList.\n"; anfind($myBase); } else { anfind($myBase); } $lastOne = $myBase; } sub noteCheck { open( A, "$anno" ); my $toGet = 0; while ( $a = ) { if ( $a =~ /^=/ ) { $toGet++; } } close(A); print "TEST RESULTS:10,$toGet,0,results\n"; } sub anfind { open( A, "c:/writing/dict/brit-1word.txt" ) || die("No dictionary file."); my $hashy = 0; print "Trying $_[0]...$myBase\n"; open( C, ">>$anno" ); if ($htmOut) { open( D, ">$anaHtm" ); print D "\n
\n