If you want to count all WORD occurrences within a string (but not within substrings), you can do the following using the goatse operator:
use strict; use warnings; my $string = 'How much wood could a woodchuck chuck if a woodchuck cou +ld chuck wood?'; my $woodCount = () = $string =~ /\bwood\b/g; print $woodCount; # prints 2
Hope this helps!
In reply to Re: Count number of occurrence of word
by Kenosis
in thread Count number of occurrence of word
by fattahsafa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |