good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Try the Substitution Operatorby chromatic (Archbishop) |
on Dec 24, 1999 at 12:02 UTC ( [id://1388]=note: print w/replies, xml ) | Need Help?? |
my $count = ($string =~ s/(foo)/$1/g); will also do the trick. Benchmarking is left as an exercise for the discerning acolyte. The match operator (/foo/) only returns a boolean to indicate that it did or did not match. Our friend Mr. Substitution gives us more data. tr/// is probably much faster for simple substrings, not regex's.
In Section
Seekers of Perl Wisdom
|
|