Subject: | Lex vars in regexp code blocks can be eclipsed |
$ perl5.12 -Mblib -MDDS -e '$sub1 = do { my $f; sub { $f } }; $sub2 = do { my $f; sub { $f } }; Dump [$sub1,$sub2]'
my ($f,$f_eclipse_1);
$f = undef;
$f_eclipse_1 = undef;
$ARRAY1 = [
sub {
$f;
},
sub {
$f_eclipse_1;
}
];
$ perl5.12 -Mblib -MDDS -e '$sub1 = do { my $f; sub { /(?{$f})/ } }; $sub2 = do { my $f; sub { /(?{$f})/ } }; Dump [$sub1,$sub2]'
my ($f,$f_eclipse_1);
$f = undef;
$f_eclipse_1 = undef;
$ARRAY1 = [
sub {
/(?{$f})/;
},
sub {
/(?{$f})/;
}
];
I see similar results with bleadperl, but without the $f_eclipse_1 definition.
$ perl5.21.7 -Mblib -MDDS -e '$sub1 = do { my $f; sub { /(?{$f})/ } }; $sub2 = do { my $f; sub { /(?{$f})/ } }; Dump [$sub1,$sub2]'
Subroutine B::OP::parent redefined at /Users/sprout/.cpan/build/B-Utils-0.25-K2jkIx/blib/lib/B/Utils.pm line 188.
$ARRAY1 = [
sub {
/(?{$f})/;
},
sub {
/(?{$f})/;
}
];
Is this something you want to bother addressing? You would have to go rummaging through the ops inside regexp objects and feed them to the deparser, to get this to work properly.
I plan to do something similar to B::Deparse (to fix not only this, but other issues), so this bug will be fixed ‘for you’ in bleadperl.
I leave it to you whether older perls should be handled, or whether this ticket should just be rejected. This is not the result of real-world code, but just something I thought of when running perl’s tests through B::Deparse.