in reply to Counting SubStrings, Style Question
my $count = 0; ++$count while ( $parent =~ /$substring/go );
...which is faster and uses less memory in my benchmarks than the =()= "operator". I also find it more readable.
Another reason split is bad: If the string ends with the substring you get 1 less in split's result.
mclapdawg:829841 juster$ perl -E 'say scalar split /xxx/, q{xxx xxx }' 3 mclapdawg:829841 juster$ perl -E 'say scalar split /xxx/, q{xxx xxx}' 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Counting SubStrings, Style Question
by LanX (Saint) on Mar 21, 2010 at 10:48 UTC |