in reply to Can a sub generate a closure from within itself?
So with the additional scope both inst and the newly generated sub will refer to the same lexical variable ($both).{ my $both; sub inst { my $inner = shift; $both .= "xxx "; return sub { printf "both: %s\nmine: %s\n", $both, $inner; }; } } for( 1 .. 3 ) { my $n = inst("[$_]"); &$n; } __output__ both: xxx mine: [1] both: xxx xxx mine: [2] both: xxx xxx xxx mine: [3]
_________
broquaint
|
|---|