On 16 Aug 2000, Perl6 RFC Librarian wrote:

> 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. 

$count = () = $variable =~ m/foo/g;

The () puts the match into list context (so the matches themselves are
returned), and that list assignment evaluated in scalar context, giving
the number of values assigned to the list.

Cheers,
Philip
-- 
Philip Newton <[EMAIL PROTECTED]>

Reply via email to