Hello moviesigh, and welcome to the Monastery!
In addition to the problem identified by kcott, there are some problems with your matching logic. Here are two:
First, note that \Q disables pattern metacharacters until the next occurence of \E (see “Escape Sequences” in Regular Expressions). But the regex in your first while loop uses the variable $mainword which has been initialised to (Steve\ Jobs|Executive), and the pipe symbol | needs to be a metacharacter for the regex logic to work.
Second, I have my doubts about the for loop — which, by the way, would be better written:
for my $dist (0 .. $distance) {
Quantifying a regex match using {0} (which is what you get on the first iteration) serves no purpose. But I don’t think you want a loop here at all? Something like {1,$dist} might better capture the intention?
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Counting the keywords in the text file
by Athanasius
in thread Counting the keywords in the text file
by moviesigh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |