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?
foo
within your own namespace (with wrapping it intopackage Mine; sub foo {} ... package main;
for example, then call it with this namespace qualifier applied? – Timberfoo
came from somewhere else entirely. It's not even mine, it just needs to be called. It prints the footer of the webpage, but I don't have influence over it. But if it's replaced by an empty sub the bottom of my webpage is missing, which feels sort of like being caught with your pants down. ;-) – Huronrequire
d file which is in use in most of the parts of the application. I don't see how I could change that. :-/ – Huron