Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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:

#/usr/bin/perl -w use strict; sub s1 { print "hi\n"; } sub s1 { print "hi 2 you\n"; } print "calling s1...\n"; s1();

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

In reply to Checking for duplicate subroutine names by SirBones

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and dust plays in a shaft of sunlight...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (1)
    As of 2018-04-20 06:09 GMT
    Find Nodes?
      Voting Booth?