Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Difference in Module loading and install??

by haukex (Archbishop)
on Nov 16, 2021 at 08:47 UTC ( #11138881=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138881]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-08-08 22:56 GMT
Find Nodes?
    Voting Booth?

    No recent polls found