in reply to Re: Debugger and lexicals
in thread Debugger and lexicals

This has nothing to do with the debugger and everything to do with closures. All the debugger does is do the equivalent of executing an eval at the point of interest in the code. Consider the following:
{ my $a = 1; sub f1 { $a; print "f1: a=", eval('$a'), "\n"; } sub f2 { print "f2: a=", eval('$a'), "\n"; } } f1(); f2();
when run, this outputs:
f1: a=1 f2: a=
(The block is there to mimic the implied block that's wrapped around a use'd file). Here, f1 creates a closure, which means it captures the initial (and in this case, only) instance of $a; i.e. a reference to $a is stored in f1's pad. During execution, when the block end is reached, $a goes out of scope for the main sub, and the reference to it from the main pad is removed. When the evals are run, the eval in f1 sees $a since that sub has captured it; whereas the f2 eval can't see it, as it wasn't captured by f2, and no longer exists in the parent.

Dave.