![]() |
|
P is for Practical | |
PerlMonks |
Counting Substrings in Stringsby CmdrTaco (Initiate) |
on Oct 27, 1999 at 04:27 UTC ( #858=perlquestion: print w/replies, xml ) | Need Help?? |
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).
Back to
Seekers of Perl Wisdom
|
|