in reply to how to declare a local *subname=sub{}?
local is a runtime command which restores at the end of the scope, given by the block markers here.
And the declaration of subs is a compile-time effect.
Obviously you are calling stuff after the restoration.
HTH your code and intentions are not very clear, this smells like a XY problem
If you want to manipulate (so called monkey patching ) which routines are called within a sub, you have to manipulate the symbol table right before calling the surrounding sub.
That is
stuff(); #original { local *asub = $code_ref; stuff(); # new behavior local (sic) only } stuff(); #original
But you don't need local if you don't need it to be restored.
I'd rather suspect you might want to look into closures and how to call lexical coderefs
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to declare a local *subname=sub{}?
by perl-diddler (Chaplain) on Oct 30, 2016 at 22:59 UTC | |
by LanX (Saint) on Oct 30, 2016 at 23:12 UTC | |
by perl-diddler (Chaplain) on Oct 31, 2016 at 12:00 UTC | |
by LanX (Saint) on Oct 30, 2016 at 23:23 UTC | |
by perl-diddler (Chaplain) on Oct 30, 2016 at 23:31 UTC | |
by LanX (Saint) on Oct 30, 2016 at 23:41 UTC | |
by LanX (Saint) on Oct 30, 2016 at 23:05 UTC | |
by perl-diddler (Chaplain) on Oct 31, 2016 at 11:57 UTC | |
by LanX (Saint) on Oct 31, 2016 at 12:35 UTC | |
by LanX (Saint) on Oct 30, 2016 at 23:37 UTC |