in reply to Accessing variable in callback running context
${ caller()."::meta" } = 1;
Caveat: Assumes the calling package and the package in which the sub was compiled is the same, so the following won't work:
package pkg3; sub foo { print "$_[0]: meta=$meta;\n"; }; package pkg2; pkg1::test1(\&pkg3::foo);
$_, $a and $b are usually used since strict doesn't complain about them. $_ is truly global, but $a and $b require using caller as above.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Accessing variable in callback running context
by brianski (Novice) on Sep 09, 2013 at 22:31 UTC |