On Jun 22, Bradford Ritchie said:

>Does anyone know how to count the number of times a regex (global)
>matches?

Either:

  $count += while /regex/g;

or

  $count = () = /regex/g;

As for the "make it list context" function, here it is:

  sub list_context { @_ }

Now you can say

  $count = list_context(/regex/g);

>Does anyone know why m//g only returns true on success instead of
>returning the number of matches like s///g and tr/// do.

//g returns true/false in scalar context, and the information about the
matches in list context.

  http://www.pobox.com/~japhy/docs/book.html

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to