No such thing as a small change | |
PerlMonks |
Re: Count number of occurrences of a list of words in a fileby Athanasius (Archbishop) |
on May 09, 2018 at 16:11 UTC ( [id://1214285]=note: print w/replies, xml ) | Need Help?? |
Hello Azaghal, The bottleneck occurs here, in the inner loop:
If %count contains 60,000 entries, then the foreach loop performs 60,000 regex tests against each line of the input text file! Fortunately, this is quite unnecessary. I would split each line into words and simply lookup these words in the hash; like this (untested):
(You may need to tweak the split regex, depending on the contents of the words in the list file.) Hope that helps,
In Section
Seekers of Perl Wisdom
|
|