Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) 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 "", 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

The script that threw the error:

use; for (1 .. 1000) { spin(); } sub spin { print "i am the second spin() sub\n"; }

I got the warning: "Subroutine spin redefined at 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:

use; for (1 .. 1000) { spin(); spin2::spin(); } package spin2; sub spin { print "i am the second spin() sub\n"; }

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.

In reply to Re: Why " subroutined redefined" warning comes? by joeface
in thread Why " subroutined redefined" warning comes? by sanjay nayak

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 all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (5)
    As of 2018-05-23 06:22 GMT
    Find Nodes?
      Voting Booth?