in reply to Count number of occurrence of word
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Count number of occurrence of word
by fattahsafa (Sexton) on Mar 09, 2014 at 18:17 UTC | |
by Kenosis (Priest) on Mar 09, 2014 at 18:18 UTC | |
by karlgoethebier (Abbot) on Mar 10, 2014 at 12:57 UTC |
In Section
Seekers of Perl Wisdom