in reply to variables from STDIN

If I understand you correctly, you're talking about using nested loops to create all the possible combinations of letters matching your pattern, and then using those to search....something.

This is going to result in extremely large arrays of strings -- way more than "thousands." A six-letter pattern containing 3 Cs and 3 Vs will result in over a million words, while a pattern like CVCCVCVCV (matching 'configure') would create over 12 billion, requiring over 100GB of space just to hold them. And in each case, only a tiny percentage of them would be actual words. (The 'configure' pattern matches 1415 words in my /usr/share/dict/words, or .000011% of the possible letter combos.)

If you're looking for actual words, and not just random assortments of letters, it's very likely that you would be better off going the other direction -- start with a dictionary of valid words, which probably won't have more than a million entries, and search it for words that match your pattern.

Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.

Replies are listed 'Best First'.
Re^2: variables from STDIN
by SuicideJunkie (Vicar) on Feb 22, 2012 at 21:31 UTC

    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.