By user "timka7060":
Who can figure this out. I narrowed down my issue in some other code to this simple use case:# Can print $v only once!!! # Second call returns undef. # Some coderef optimization??? # Lexical variable goes undef on second call. # sub { my $v = 111; eval q( eval 'print $v, "\n"'; # 111 eval 'print $v, "\n"'; # undef ); }->();
User "tyrrminal" replies with:
If you enable warnings, you see a line Variable "$v" is not available at (eval 3) line 1. Googling that led me to a stack overflow response which seems to relate to your case (2nd answer, starting with See perldiag)
timka7060's reaction:
So why does the first eval output 111?
(I'd figure either both lines should be 111 or both undef.)
Btw, prior to 5.10, both lines would output 111: https://perlbanjo.com/b28dce8db2
This is a simple fix, but only for a single variable: https://perlbanjo.com/13dbb8d48d
My observation:
Now, none of either A or B sees $v, but C (obviously) does.sub { my $v = 111; eval q( eval 'print $v, "A\n"'; eval 'print $v, "B\n"'; print $v, "C\n"; ); }->();
What's going on here?
In reply to Lexical variable not available by choroba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |