On Thu, Jun 14, 2001 at 05:08:30PM -0400, Carl Rogers wrote:
>
> >
> >$string =~ /a/g; # match on all 'a' in $string
> >
> >Now how do I know how many times it actually matched?
>
> Try:
> $result = $string =~ /a/g;
> The value will be in $result
> perl -wle '$str = "abcabcabc"; $cnt = $str
Oops! Sorry! Wrong section of the documentation. I meant to grab the
paragraph a little further down. Still in perlop, still in the Regexp
Quote-Like Operators section:
The /g modifier specifies global pattern matching--that is, matching as
many times as possible within the string. How i
At 05:08 PM 6/14/2001, you wrote:
>Try:
>$result = $string =~ /a/g;
>The value will be in $result
>
>Carl
Close. You have to force list context for the result of the pattern match
to make it work. Like this:
$result = () = $string =~ /a/g;
(Thanks to Mark-Jason Dominus)
Check out perlop for
Original Message-
From: Carl Rogers [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 14, 2001 14:09
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: counting regex matches
>
>$string =~ /a/g; # match on all 'a' in $string
>
>Now how do I know how many times it actua
>
>$string =~ /a/g; # match on all 'a' in $string
>
>Now how do I know how many times it actually matched?
Try:
$result = $string =~ /a/g;
The value will be in $result
Carl