http://qs1969.pair.com?node_id=11138881


in reply to Difference in Module loading and install??

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.