in reply to scoping across parent/child relationship
1) pass the variables to the sub (recomended)
2) create the sub within the else block (not recomended).
Just to further explain, here's some example code that will give you the same results.
Or if it existed inside the scope (not recomended, just for demonstrative purposes)# $foo and $bar are not accessable outside of this scope { my ($foo, $bar) = qw(Hello world); DoSomething(); } # this is outside of the above scope so it can not access $foo and $ba +r sub DoSomething { print "$foo $bar\n"; }
Hope this helps# $foo and $bar are not accessable outside of this scope { my ($foo, $bar) = qw(Hello world); DoSomething(); # this is inside the scope so it can access $foo and $bar sub DoSomething { print "$foo $bar\n"; } }
|
|---|