in reply to Re: Making lexically-scoped ref available to non-OO subs in another package
in thread Making lexically-scoped ref available to non-OO subs in another package
package The::Package { use Carp; use base "Exporter"; BEGIN { our @EXPORT = qw( my_generator foo takes_coderef ) }; my $scratchpad; sub my_generator (&) { $scratchpad = {}; shift->(); my $tmp = $scratchpad; undef $scratchpad; return $tmp; }
Just when I thought I was getting the hang of Perl..! I had no idea a my package variable would work like this.
I'm amazed at the elegance of this, and that you came up with this rather instantaneously. Thank you!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Making lexically-scoped ref available to non-OO subs in another package
by tobyink (Canon) on Jul 13, 2013 at 07:35 UTC |