R
Roy Johnson
If you short-circuit out of a global pattern match like so:
for (1..$n) {
$str =~ /($pat)/g;
$NthMatch = $1;
}
where there are more than $n matches, the next time you do
$str =~ /($pat)/g;
even if it's in a completely different block of code, the matching is
going to pick up where it left off. Is there a way to reset it, short
of whiling away the rest of the matches? (I tried several arguments
for the reset function.)
Incidentally, the best way to get the $nth match of $pat in $str is
$str =~ /(?:.*?($pat)){$n}/;
but I'm still curious about short-circuited global matches.
for (1..$n) {
$str =~ /($pat)/g;
$NthMatch = $1;
}
where there are more than $n matches, the next time you do
$str =~ /($pat)/g;
even if it's in a completely different block of code, the matching is
going to pick up where it left off. Is there a way to reset it, short
of whiling away the rest of the matches? (I tried several arguments
for the reset function.)
Incidentally, the best way to get the $nth match of $pat in $str is
$str =~ /(?:.*?($pat)){$n}/;
but I'm still curious about short-circuited global matches.