in reply to Getting the number of times a regexp matches
Everyone so far seems to have missed this bit of evil context bashing:
$num_matches = () = $string =~ m/pattern/g;This works because the () force the far right hand side to be evaluated in list context, the result of which is then reevaluated in scalar context to give the result. This is a nice example using side effects to good cause in perl.
|
---|
Replies are listed 'Best First'. | |
---|---|
(tye)Re: Getting the number of times a regexp matches
by tye (Sage) on Dec 07, 2000 at 22:39 UTC | |
Re: Re: Getting the number of times a regexp matches
by japhy (Canon) on Dec 07, 2000 at 18:30 UTC | |
Re: Re: Getting the number of times a regexp matches
by MeowChow (Vicar) on Dec 07, 2000 at 23:53 UTC | |
by tye (Sage) on Dec 08, 2000 at 00:39 UTC | |
by Fastolfe (Vicar) on Dec 08, 2000 at 00:47 UTC |
In Section
Seekers of Perl Wisdom