OK. So the core of what you have:
reads the file line by line into $text, and then tries each column 1 word (captured earlier as the key values in your %hash). The regex /\b$key\b/ig is plausible, and the [oi] stuff will do what you want -- the [Nn] will also work, but are redundant because of the i qualifier of the regex.while (my $text=<$testo>){ for my $key (keys %hash){ my $value = $hash{$key}; my $arrkey=$key." "; my $count = 0; $count += () = /\b$key\b/ig while <>; print $conteggio "$arrkey) => $count\n"; } ; } ;
The rest is, frankly, a dogs breakfast and can be thrown away.
To count the number of times you get a match in each line,
is sufficient, but fairly deep magic. This:my $count = () = $text =~ /\b$key\b/ig ;
may or may not seem clearer.my $count = 0 ; while ($text =~ /\b$key\b/ig) { $count++ ; } ;
Now your problem is how to collect the count for each word across all the lines of your input. I suggest using the value part of your hash entries to hold the count for the word in the key part.
When the while loop has finished, your hash should contain the count for each word, which you can then output to $coteggio.
In reply to Re^3: Counting occurence of a list of word in a file
by gone2015
in thread Counting occurence of a list of word in a file
by b_vulnerability
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |