in reply to Re^2: Counting words..
in thread Counting words..
It puts the match into array context, which causes it to return the matches; then the resulting array is taken as a scalar, resulting in the count. This is a somewhat common Perl idiom. And you don't have to reset the counter.$count = () = /$keyword/ig;
Of course, if you need to accumulate several counts, make it += instead of =, and do remember to reset the counter.
|
|---|