2008/6/5 Yuval Kogman <nothingmuch@woobling.org>: > It appears that ??{ } behaves like a closure only on it's first > invocation, and not at the time that is actually > compiled/encountered lexically: > > use Test::More 'no_plan'; > > use re 'eval'; > > { > use re "eval"; > > my $foo; > > my $bar = qr{ (a+) ((??{$foo})) }x; > > $foo = qr{ b+ }x; > > sub match { > # uncommenting this retains $foo, and makes the tests pass > #{ no warnings 'void'; $foo; } # force capture of interpolated lexical > $_[0] =~ m{ $bar }x; > return ($1, $2); > } > > # uncommenting this also retains $foo > #is_deeply([ match("aaabb") ], [qw(aaa bb)]); > } > > is_deeply([ match("aaabb") ], [qw(aaa bb)]); > > > This test fails because $foo is uninitialized in the execution of $bar. > > However, if $bar is executed once before $foo's scope is left then it will be > retained, and likewise if the subroutine forces $foo to be captured then it is > also retained, and the matching succeeds. > > I'm guessing this is a bug? That's known. I think Dave has plans to fix that (but it won't be completely trivial).Thread Previous | Thread Next