in reply to Re: all occurences of a target word by regular expression
in thread all occurences of a target word by regular expression
@count=$string=~m/apple/g; ... , scalar @count, ...
You can get the count directly using this construct.
$ perl -E ' > $str = q{I like apples, pears and pineapples}; > $count = () = $str =~ m{apple}g; > say $count;' 2 $
I hope this is of interest.
Cheers,
JohnGG
|
|---|