Hi,
I want to search the contents of files in a directory for words present in files in another directory. Is there a better way to do it than the following? (By better mean memory usage wise)
More specifically:
folder 1 has several files, each file has several lines of text. folder 2 has several files, each file has several words, each on its line. What I want to do is count the number of occurrences of each word in each file in folder 2 in each line of each file of folder 1. I hope that wasn't too confusing.
open my $output, ">>D:/output.txt";
my @files = <"folder1/*">;
my @categories = <"folder2/*">;
foreach my $file (@files){
open my $fileh, $file || die "Can't open file $companyName";
foreach my $line (<$fileh>){
foreach my $categoryName (@categories){
open my $categoryFile, $categoryName || die "Can't open file $categoryName";
foreach my $word(<$categoryFile>){
#search using regex
}
#print to output
}
}
}