Hi Monks,
In the script below, the lexical variable $lost is not visible to &test_sub2 which is what I expected. But I wonder why lexical variable $tricky is visible to &test_sub? How does Perl treat the lexical variables defined in the main script differently from those defined in a block?
Thanks in advance :-)
#!/usr/bin/perl my $tricky = "in main"; &test_sub; sub test_sub { print "$tricky\n"; my $lost = "gone"; &test_sub2; } sub test_sub2 { print "$lost\n"; }
The script above prints "in main".
In reply to Scope of lexical variables in the main script by sophate
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |