develooper Front page | perl.perl6.language.regex | Postings from August 2000

Re: RFC 110 (v3) counting matches

Thread Previous | Thread Next
From:
Tom Christiansen
Date:
August 28, 2000 11:23
Subject:
Re: RFC 110 (v3) counting matches
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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About