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.