Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: help with scoping (code), part 1

by Fastolfe (Vicar)
on Nov 04, 2001 at 03:20 UTC ( [id://123109]=note: print w/replies, xml ) Need Help??


in reply to help with scoping (code), part 1

I'm not sure I parsed your question correctly. How do you tell if sub_two is a "help" sub? What is a "help" sub? What do you need to call all of the subs in @children? This anonymous subroutine in sub_two? And when you say "all of the subs", you mean sub_one and sub_two, yes?

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:

{ my @children = ( ... ); sub sub_two { ... } foreach my $child (@children) { if ($child->(...)) { ... } else { ... } } }
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.

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://123109]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found