Unfortunately, I'm having a bit of trouble understanding parts of your description. A Short, Self-Contained, Correct Example that we could use to reproduce your situation would go a long way in demonstrating your exact situation and would allow us to answer quicker and better.

This script contains line "package That::Module" to use the subroutine of a package in a module.

Note that package does not load another module, all it does is define that the following code is in that namespace. Using package to access the code defined in another package is not recommended - by that I mean, for example, if there is a module Other::Module containing a sub foo, one could theoretically write package Other::Module; to switch to that namespace and then call foo(), provided that some other piece of code has loaded Other::Module. Instead, one should either write Other::Module::foo() to call that function, or use an import mechanism like use Other::Module qw/foo/; (provided that Other::Module has implemented this).

I want to know how my simulation script runs successfully without the phrase "use".

I have to guess, but perhaps this is because some other module somewhere is already loading that module. So for example, if your script does use My::Module;, and My::Module does use Other::Module;, then your script could access Other::Module. However, this is not a best practice, and your script should explicitly load all of the modules it wants to make use of.

And want to know how to add(or load? or install? I have some confusion about this.) module and run script2 without the phrase "use" in my test directory.

The use is generally necessary to load a module. There are some alternatives like require but that is often not the best practice. If your question is rather about @INC, which lists the directories where use looks for modules, there are multiple ways to add custom directories there as well.

The term "installing" a module typically refers to downloading a module e.g. from the CPAN using a tool like cpanm. Sometimes, it is used more loosely to mean copying a .pm file into one of the @INC directories.

Edit: Typo fixes.


In reply to Re: Difference in Module loading and install?? by haukex
in thread Difference in Module loading and install?? by Lewis

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.