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 | |
by flounder99 (Friar) on Jul 26, 2003 at 03:08 UTC |