I'm working with legacy code and have to require
a .pl file that defines a sub foo
. My problem is that in my main::
namespace there already is another sub foo
, which is called later in a part of the program I'm currently not dealing with.
The file I require defines sub foo {}
because obviously it does not want the foo things to happen where it is usually called. In my case, that is bad.
I've tried playing around with the *foo
glob:
*old_foo = *foo;
require 'foo_killer.pl';
*foo = *old_foo;
Of course, that doesn't work since I've only created an alias (as brian d foy points out on page 133 of Mastering Perl) and thus *old_foo
will point to the now 'empty' subroutine.
Is there a way to somehow copy what's in *foo{CODE}
to somewhere else instead of aliasing it? Or is there maybe another approach to solve this?
Try like this
{
local *foo;
require 'foo_killer.pl';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With