open (CORPUS, "little_corpus.txt") or die "Warning! Can't open corpus file $!\n"; while ($line = ) { chomp($line); for ($i = 0; $i < length($line) - 1; $i++) { # The following stores the current character in a "hash table" $sequences{substr($line, $i, 2)} = 1 ; } } # Get a list of all the items in the inventory hash table @found_seqs = keys %sequences; print "List of all two-char sequences in the file (" . scalar(@found_seqs) . " total)\n"; foreach $seq (@found_seqs) { print "$seq " } 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) - 1; $i++) { if (not exists $sequences{substr($line, $i, 2)}) { print "Word $line is illegal (Sequence " . substr($line, $i, 2) ." not in corpus inventory)\n"; $legal = 0; last; } } if ($legal) { print "Word $line is legal\n"; } }