[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
??{ } closure semantics
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?
--
Yuval Kogman <nothingmuch@woobling.org>
http://nothingmuch.woobling.org 0xEBD27418
PGP signature
- Follow-Ups from:
-
"Rafael Garcia-Suarez" <rgarciasuarez@gmail.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]