Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Module usage

by ig (Vicar)
on Feb 26, 2009 at 09:53 UTC ( [id://746500]=note: print w/replies, xml ) Need Help??


in reply to Module usage

This is essentially the same answer as others have provided but if you don't understand their answers perhaps this manner of expressing them will help...

'use Mymodule ();' causes Mymodule to be loaded without calling its import() subroutine. This makes the subroutines of the module available and will cause BEGIN, UNITCHECK, CHECK and INIT blocks to be executed if they exist.

The import() subroutine of many (not all) modules will add variables or subroutines to the callers name space.

You sometimes want to load the module but do not want it to add anything to your name space. For example - you may have your own subroutines of the same name as the module would create (import) if its import() subroutine was called.

Having loaded the module, you can access its subroutines using fully qualified subroutine or method calls. For example, Mymodule::some_subroutine() or Mymodule->some_method.

In some modules the import() subroutine does other things as well as or instead of importing names into the callers name space. If the module is doing initialization in its import() subroutine, then it may not work as expected when you prevent the subroutine being called. You should read the documentation or the code of the module you are using to be sure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-24 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found