in reply to Count substitutions by s///g

my $num_substitutions = $var =~ s/foo/bar/g;

Quoting from perldoc perlop:

s/PATTERN/REPLACEMENT/egimosx Searches a string for a pattern, and if found, replaces + that pattern with the replacement text and returns the numbe +r of substitutions made. Otherwise it returns false (specif +ically, the empty string).

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Count substitutions by s///g
by Anonymous Monk on Jul 25, 2003 at 20:33 UTC
    Crap, I've been using it as: if (s///) {} thinking it was just returning success/failure. That was a stupid question: thanks.