in reply to Doubly-nested deeply bound variable is undefined
Notice, that within foo() \$x refers to a different location than \$x in the parent scope.sub test_sub { print &{+shift}; } { my $x = "hello"; my $y = "world"; local $, = " : "; print "x - local lexical1 : $x ", \$x; print "y - local lexical1 : $y ", \$y; sub foo { test_sub( sub { "x - derived lexical (anon) : $x ", \$x } ); print "y - derived lexical (foo) : $y ", \$y; test_sub( sub { "y - derived lexical (anon) : $y ", \$y } ); sub bar { sub baz { print "x - derived lexical (baz) : $x ", \$x; } } } print "x - local lexical2 : $x ", \$x; print "y - local lexical2 : $y ", \$y; } foo(); baz(); __END__ __output__ x - local lexical1 : hello : SCALAR(0x814c630) y - local lexical1 : world : SCALAR(0x814c6f0) x - local lexical2 : hello : SCALAR(0x814c630) y - local lexical2 : world : SCALAR(0x814c6f0) Use of uninitialized value in concatenation (.) or string at foo line +17. x - derived lexical (anon) : SCALAR(0x814bc28) y - derived lexical (foo) : world SCALAR(0x814c6f0) y - derived lexical (anon) : world SCALAR(0x814c6f0) x - derived lexical (baz) : hello SCALAR(0x814c630)
|
|---|