|more useful options|
Re: Why " subroutined redefined" warning comes?by joeface (Pilgrim)
|on Nov 04, 2006 at 19:10 UTC||Need Help??|
Admittedly, I'm not the sharpest tool in the shed when it comes to packages, modules, namespaces, and OO-related Perl stuff, but I worked around the same warning earlier today.
I have a module called "Spinner.pm", that contains a subroutine called "spin()". I created another sub in the main script called "spin()". So, Perl didn't seem to know whether to use the sub in Main::, or the sub in Spinner.pm.
The script that threw the error:
I got the warning: "Subroutine spin redefined at script.pl line 21". Perl then went ahead and used the spin() sub that was in the main script.
I got around this by doing the following:
By explicitly specifying package::subroutine(), Perl knew which one to use. I got the functionality of both calls, with no warnings.
So, although I agree with davido, and would advise against giving a sub the same name as one that already exists in one of your loaded modules (or in your main script), if you have to do it, you have to put the "duplicate" sub in a different package. Note that I have no idea how this would affect your variable scoping, or whatever else is going on in your script.