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.
In reply to Re: Getting the number of times a regexp matches
by quidity
in thread Getting the number of times a regexp matches
by MeowChow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |