Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: Catching closures

by hipowls (Curate)
on Mar 06, 2008 at 10:09 UTC ( [id://672419]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Catching closures
in thread Catching closures

I guess to be really pedantic that should be it shares a copy with stuff declared in the same scope at the same time.but functions declared on entering the same scope later get their own set of shared variables. I take your point though and stand corrected.

I read CountZero's reply and I now understand the OP's concern but I don't see that debugging a variable that has leaked into a closure is any harder than debugging the same problem with regular functions.

my $var; sub the_first { $var = func1(); } # many, many lines of code later sub the_second { $var = disfunction(); }
and in most cases the closures are declared together so it is probably easier to spot.

I think the answer is to be careful with variables, restricting them to as small a scope as possible and to have as few as possible with file scope.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-24 10:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found