in reply to anonymous sub, packages, global variables
For simplicity the following code is a cut&paste from my scratchpad, (had to help KennethK in the CB to figure it out)
use strict; use warnings; $\="\n"; *tst=sub { print "orig" }; tst(); my $safe=\&tst; { no warnings; *tst=sub { print "new"}; } tst(); { no warnings; *tst=$safe; } tst();
it shows how to safe, replace and reestablish a function.
If you use local *tst=sub {...} you can also restrict the new function till the end of scope.
Cheers Rolf
|
|---|