The easiest approach is to simply repeat the logic of the first while loop and create a second hash containing the words in the second text file. (It will help if you rename the first hash %results to something like %words1, then the second hash can be named %words2.) You now have only to find which keys are common to both hashes, and that will give you the desired result:
This is good advice; there's also List::Compare::Functional, which may make it easier to get the intersection of the two, e.g. (untested):
use feature qw/say/; use List::Compare::Functional qw/get_intersection/; # ... my @common = get_intersection( [keys %words1], [keys %words2] ); my $counter = scalar @common; # output common words say join "\n\n", @common; # output count; say "Found $counter words in common."
EDIT: of course it's $counter, not $common; thanks Athanasius. (See what I meant about "untested"?)
In reply to Re^2: Extracting common words
by AppleFritter
in thread Extracting common words
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |