in reply to help with scoping (code), part 1
So basically, the problem is that you need this subroutine sub_two to be able to access @children, yes?
In your other question, a poster discussed the use of a simple block to wrap around your functions:
So long as the subroutine in question is declared within the same lexical scope as the variable, you're OK. This may mean you need to move 'my @children = (...)' higher up in your file, or use our instead of my as you suggest.{ my @children = ( ... ); sub sub_two { ... } foreach my $child (@children) { if ($child->(...)) { ... } else { ... } } }
After that, you can execute these subroutines in any fashion, and they'll still end up seeing the same variables in the same lexical scope.
|
|---|