in reply to Re^2: Count number of occurrence of word
in thread Count number of occurrence of word
Then show your test, because it does work:
As you can see in this Perl one-liner, I print successfully the number of occurrences of "foo" in my $string.$ perl -e 'my $string = "foobarfoofoobarfoo"; my $count = $string =~ s +/foo/foo/g; print $count;' 4
Or, perhaps I didn't understand part of your requirement. What do you mean by substring? Possibly you want this:
my $count = $string =~ s/\bfoo\b/foo/g;
Edit: Yes, from your answer to Kenosis, I see now that I had not understood what you meant when talking about substring, sorry. The last solution I posted above should work in accordance with your needs.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Count number of occurrence of word
by fattahsafa (Sexton) on Mar 10, 2014 at 21:17 UTC | |
by Laurent_R (Canon) on Mar 10, 2014 at 21:50 UTC |