Re: RFC 110 (v3) counting matches

[email protected] (Tom Christiansen)
Newsgroups perl.perl6.language.regex
Message-ID <12038.967487028@chthon>
>Have you ever wanted to count the number of matches of a patten?  s///g 
>returns the number of matches it finds.  m//g just returns 1 for matching.
>Counts can be made using s//$&/g but this is wastefull, or by putting some 
>counting loop round a m//g.  But this all seams rather messy. 

It's really much easier than all that:

    $count = () = $string =~ /pattern/g;

--tom
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.