Just another Perl shrine | |
PerlMonks |
Scope difference between compile-time and run-time ( if( my $x = ... ) {...} )by LanX (Saint) |
on Jun 01, 2021 at 18:43 UTC ( [id://11133380]=perlquestion: print w/replies, xml ) | Need Help?? |
LanX has asked for the wisdom of the Perl Monks concerning the following question:
Perl has some - IMHO buggy - behavior if a lexical declaration happens in the head and not the body of a compound construct like if(HEAD){BODY} . The compile-time scope ends right after the BODY is closed, hence the lexical is not anymore declared. But the run-time destruction will only happen if the outer-scope - that's at least the file-scope° - is finished. Any reason why? In my book that's a design flow at least. DEMO:
will produce this output
DISCLAIMER: This was just discussed at German.PM online meeting today and was motivated by this SO-Discussion.
Cheers Rolf
updates
Back to
Seekers of Perl Wisdom
|
|