open (CORPUS, "little_corpus.txt") or die "Warning! Can't open corpus file $!\n"; while ($line = ) { chomp($line); for ($i = 0; $i < length($line); $i++) { # The following stores the current character in a "hash table" $inventory{substr($line, $i, 1)} = 1 ; } } # Get a list of all the items in the inventory hash table @phonemes = keys %inventory; print "List of all phonemes in the file (" . scalar(@phonemes) . " total)\n"; foreach $phoneme (@phonemes) { print "$phoneme " } print "\n"; open (TEST, "test_words.txt") or die "Warning! Can't open file of test words: $!\n"; while ($line = ) { chomp($line); $legal = 1; for ($i = 0; $i < length($line); $i++) { if (not exists $inventory{substr($line, $i, 1)}) { print "Word $line is illegal (" . substr($line, $i, 1) ." not in corpus inventory)\n"; $legal = 0; last; } } if ($legal) { print "Word $line is legal\n"; } }