the count is off ... man ... help please.
The Code
open (FILE1, "xy1.TXT") or die "$0: Could not open SOURCEFILE.TXT: $!\n";
open (FILE2, "xy2.TXT") or die "$0: Could not open RESULTFILE.TXT: $!\n";
chomp(my @strings = <FILE2>);
while (1) {
foreach $pattern (<FILE1>) {
chomp($pattern);
last if $pattern =~ /^\s*$/;
my @matches = eval {
grep /$pattern/, @strings;
};
if ($@) {
print "Error: $@";
} else {
my $count = @matches;
print "$count lines in the result file contain: $pattern \n"
}
}
exit;
}
///////////////////////////////////////////
the files
C:\perl>type cv1.txt
car
boat
house
girl
hate
C:\perl>type cv2.txt
boy
car
girl
dog
car
love
hate
boat
boat
hate
boat
boat
boy
girl
dog
///////////////////////////////////////////
The output
C:\perl>grepc.pl
0 lines in the result file contain: car
4 lines in the result file contain: boat
0 lines in the result file contain: house
2 lines in the result file contain: girl
2 lines in the result file contain: hate