in reply to Context propagation into subs and evals
As far as I am aware, there are only two situations in which the context of a subroutine can affect or refer in any way to the context of its caller, viz:
Note how the function returned by sub bar references the local variable $foo and how the value remains accessible when the main-program invokes the subroutine (“closure”...) denoted by that result.sub bar { my $foo="bar"; return sub { print "foo is $foo\n"; } } my $fn = bar(); &$fn; foo is bar
eval has two distinct meanings: on-the-spot evaluation of the contents of a character string, and trapping of run-time errors. In both instances, AFAIK, they are treated as lexical blocks occurring at that point. (In the latter case, the block would be the same even if the keyword eval did not precede it.)
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Context propagation into subs and evals
by LanX (Saint) on Feb 20, 2012 at 14:22 UTC |