Having a circular dependency like this is generally a sign of tight coupling, which is a bad thing. Other people have suggested that you create modules. That is just a way to repackage the problem so it shows up in a different way. See my reply to ikegami for an explanation of how it shows up if you do that.

The safe solution is to move one require inside of a function call. So, for instance, move the require of libB.pl into subroutine A. This is only going to actually load the other library once, so don't worry about performance. For an example of this in the Perl core, Carp needs to use Exporter to export functions, and Exporter uses Carp to report problems. In that case Carp is loaded on demand from within Exporter.

This solves the real problem, but does nothing about your fairly harmless warning. To remove your warning you merely need to write a script that requires one of the libraries rather than run the libraries as programs in their own right.

(Random tip. Renaming libA.pl to libA.pm and putting a package statement in it is a very easy change to make, and brings all sorts of side benefits. You can use Exporter to export functions, and as a bonus it will be easier when debugging to figure out which functions came from where.)


In reply to Re: Redefined subroutines in multiple libraries by tilly
in thread Redefined subroutines in multiple libraries by James Board

Title:
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, details, 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, summary, 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.