Hi everyone,

I have two potentially basic questions about packages and scoping. I am self taught so I think that there may be a chance that there is something basic I'm not understanding here that can clear this up immediately. I have two different Perl modules, let's say package A and B.

Let's say that Package A uses Package B. However, as things become more complex, we find out that Package B needs to use some subroutines from Package A as well.

We know that we cannot just put use B; in Package A AND use A; in Package B because that would cause a circular reference. Also, we noticed that package B can call Package A subroutines directly without using use A;. While I can understand that there are package wide variables that can be accessed between the two packages, I don't understand how package B can call package A subroutines without using use A;

So the questions are:

1) What is the proper way to have package A and package B use each others subroutines without causing a circular reference?

2) Why is it that package B can use package A subroutines without using use A;

Let me know if more details are needed on my question - I hope that was clear.


In reply to Preventing Circular References in Modules by ramensaurus

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.