If it was loaded via require or use, yes, it is only compiled and executed the first time. It's import method will be called each time, allowing symbols to be exported into multiple namespaces.

# script.pl use Module1; use Module2;
# Module1.pm package Module1; BEGIN { print("Compiling Module1\n"); } use Module2; sub import { print("Module1 exporting to ". caller() . "\n"); } print("Executing Module1\n"); 1;
# Module2.pm package Module2; BEGIN { print("Compiling Module2\n"); } sub import { print("Module2 exporting to ". caller() . "\n"); } print("Executing Module2\n"); 1;
>perl script.pl Compiling Module1 Compiling Module2 Executing Module2 Module2 exporting to Module1 Executing Module1 Module1 exporting to main Module2 exporting to main
>perl script.pl | sort Compiling Module1 --> once Compiling Module2 --> once Executing Module1 --> once Executing Module2 --> once Module1 exporting to main --> once per "use" Module2 exporting to main \ Module2 exporting to Module1 --> once per "use"

In reply to Re^3: modules using things from other modules by ikegami
in thread modules using things from other modules by Anonymous Monk

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.