thewebsi has asked for the wisdom of the Perl Monks concerning the following question:
Looking for some ideas / advice...
I have a method that offers a callback feature. The running context has a variable $meta declared lexically using my. I would like to make that variable available to the callback function somehow. I have considered the following options:
All these solutions seem ugly to me, but just wondering if anyone has other ideas or sees any reason to prefer one method over the other...
#!/usr/bin/perl #use strict; package pkg1; sub test1 { my $meta = 1; $_[0]->(1); eval { $_[0]->(2) }; eval '$_[0]->(3)'; } package pkg2; { pkg1::test1 ( sub { print "$_[0]: meta=$meta;\n"; } ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing variable in callback running context
by moritz (Cardinal) on Oct 13, 2011 at 05:17 UTC | |
|
Re: Accessing variable in callback running context
by ikegami (Patriarch) on Oct 13, 2011 at 05:23 UTC | |
by brianski (Novice) on Sep 09, 2013 at 22:31 UTC | |
|
Re: Accessing variable in callback running context
by brianski (Novice) on Sep 09, 2013 at 22:27 UTC |