G'day TJCooper,
I got to this thread rather late. I'm unclear as to what happened with deletes and updates in your OP. Given what's there at the moment, this technique should do what you want:
#!/usr/bin/env perl -l use strict; use warnings; use Inline::Files; my %found; /^>(.*)\Z/ and $found{$1} = 0 while <REFERENCE_FILE>; my $re = '\b(' . join('|' => keys %found) . ')\b'; while (<SEARCH_FILE>) { ++$found{$1} while /$re/g; } print "$_ occurs: $found{$_}" for sort keys %found; __REFERENCE_FILE__ >Apple ignored blah blah blah >Banana ignored blah blah blah >Grape ignored blah blah blah __SEARCH_FILE__ Apple Banana Avocado Orange Grape Apple Apple Banana Banana
Output:
Apple occurs: 3 Banana occurs: 3 Grape occurs: 1
I've used Inline::Files for demonstration purposes. You'll need to open your real files. I recommend you read the documentation and get into the habit of using the 3-argument form with lexical filehandles. Furthermore, if you're not going to write code to check your I/O, you should consider using the autodie pragma.
-- Ken
|
|---|