|more useful options|
Checking for duplicate subroutine namesby SirBones (Friar)
|on Oct 12, 2012 at 15:32 UTC||Need Help??|
SirBones has asked for the
wisdom of the Perl Monks concerning the following question:
Hello; as usual I humbly admit my lack of Perl knowledge and ask for your kind assistance. I have tried the documentation but nothing leaps out at me.
I have observed that the following (poorly styled code, duplicate subroutine names and all) compiles and runs just fine:
OK, that seems to run the second "s1()".
Cut to a fairly large "command processor" I developed to send individual test control statements from a simple prompt to some machines we run. One of the options I have added to this tool is the ability for users to define their own Perl subroutines in an external file, and then issue a command to "include" that file in the test control tool. I suck this file in via a "require", and then the user can issue his own customized commands running his own Perl code. Works great.
My dilemma is: The base tool has dozens of subroutines, and I fear that a user will inadvertently define a sub with the same name as one of my base ones. This could be a Bad Thing. I had originally thought Perl would yell at me when I tried to "require" such a file, but apparently Perl does not mind duplicate subroutine names (thus my example above.)
I could solve this by keeping a list of all my subroutine names and then comparing them with the ones the user proposes and refusing to load his file if I pick up a duplicate. But I was wondering (out of laziness) if there was already a way for Perl to pick up on this and flag a problem on the fly, without my having to write a checker procedure.
Thanks muchly (as usually).
"This bounty hunter is my kind of scum: Fearless and inventive." --J.T. Hutt