in reply to Counting the keywords in the text file

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,

Replies are listed 'Best First'.
Re^2: Counting the keywords in the text file
by moviesigh (Initiate) on Dec 05, 2013 at 01:15 UTC

    Thank you very much for your comments. I will try to check and fix the problems you mentioned!

    Sean