CmdrTaco has asked for the wisdom of the Perl Monks concerning the following question:
Whats a clean way to count the occurances of a substring
withing a string? I've been using $x++ while /foo/g; to count the
occurances of 'foo' within $_, but it really seems like $x=/foo/g;
ought to (in scaler context) return a count, but for some reason it
always returns either undef or 1 (eg, a boolean).
|
---|
Replies are listed 'Best First'. | |
---|---|
Try the Substitution Operator
by chromatic (Archbishop) on Dec 24, 1999 at 12:02 UTC | |
Re: Counting Substrings in Strings
by pschoonveld (Pilgrim) on Dec 02, 1999 at 12:03 UTC | |
Re: Counting Substrings in Strings
by audreyt (Hermit) on Aug 05, 2002 at 22:51 UTC |
Back to
Seekers of Perl Wisdom