in reply to Re: Delimited Backtracking with Regex
in thread Delimited Backtracking with Regex
I've been asked why I used a package variable instead of a lexical variable. It's because regexps close around the lexicals that exist when they are first run.
# pass 1 2 3 # --- --- --- sub test { my @matches; '' =~ / (?{ push @matches, 'a' }) (?{ print(scalar(@matches), "\n") }) # 1 2 3 /xg; print(scalar(@matches), "\n"); # 1 0 0 } test() for 1..3;
A variable called @matches is created everytime test is called. The regexp always uses the variable from the first call.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Delimited Backtracking with Regex
by blokhead (Monsignor) on Apr 21, 2006 at 03:07 UTC |
In Section
Seekers of Perl Wisdom