Hi everyone!
I'm new here and pretty much new to Perl, sorry if my question should sound lame but I really need your help..
I have a text file containing queries, one per row.
I put these query inside an array. What I want to do next is search a whole text file - sort of a dictionary (which has one entry per row and is formatted like this: word1]definition)for occurrences of the words contained in the array.
My code is the following:
open(HH, "<$PATHDATA/query.txt");
open(XX, "<$PATHDATA/dictionary.txt");
open(DD, ">$PATHDATA/query_results.txt");
my $query;
my $line="";
$i=0;
my @query;
while(<HH>){
chomp;
push @query,$_;
}
foreach $query (@query) {
while($line=<XX>){
if ($line =~ m/^($query)\].*/i) {
print DD "MATCH:$line\n";
if($debug){
print GREEN, "QUERY:$query\n";
print MAGENTA, "MATCH:$line\n";
}
}
}
}
I'd like to have something like this as an output:
QUERY:facebook
MATCH:facebook]social network....
The code I posted get me only the first result (because facebook is actually the first element in my array).
How can I get it to print every match for every possible query?
Thanks for your help,
Giu