http://www.perlmonks.org?node_id=109136


in reply to scoping across parent/child relationship

my ( $foo, %bar, $bax ); is scoped within the else. It doesn't look like Initialize_child exists within that scope. I think there are two options, of which I think only one would be recomended.

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.

# $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"; }
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 inside the scope so it can access $foo and $bar sub DoSomething { print "$foo $bar\n"; } }
Hope this helps
Rich