in reply to Re: variables from STDIN
in thread variables from STDIN
If you want to find matching real words many times, I'd suggest building a hash of your dictionary first.
Foreach word in the dictionary, check the letters in sequence, and browse your way down a three-way hash. Add that word to an array at the end of the path.
EG: When you get to "apple", follow:
my $pos = $dictionary; #this would be a loop of course. $pos = $pos->{vowel}; # The A $pos = $pos->{cons}; # First P $pos = $pos->{cons}; # Second P $pos = $pos->{cons}; # The L $pos = $pos->{vowel}; # The E #end loop push @{$pos->{words}}, "apple";
This way you can find all words with a specific pattern of Vowel/Consonant extremely fast.
$dictionary->{vowel}{cons}{cons}{cons}{vowel}{words} will include apple, uncle, intro, extra, ochre and many more. $dictionary->{vowel}{words} would contain "I" and "a"
Alternatively, if you are planning to do only one search, you could build a regex string full of [aeiou]s and [^aeiou]s, then grep your dictionary.
|
|---|