Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Difference between use Module::Name and use Module::Name qw /method1 method2/

by moritz (Cardinal)
on Jan 29, 2013 at 10:44 UTC ( #1015845=note: print w/ replies, xml ) Need Help??


in reply to Difference between use Module::Name and use Module::Name qw /method1 method2/

In this specific case, supplying an import list (the qw/is_valid/ part) imports that symbol, leaving it out imports nothing.

In the general case, the import list is passed to the loaded module's ->import function, and it can do whatever it wants to do.

But many, many modules are based on Exporter. For Exporter-based modules, not specifying an import list gets you all the symbols listed in the default exportation list called @EXPORT. Specifying an import list disables that default, and instead gives you the symbols you asked for, if they are listed in @EXPORT_OK. If they are not, you'll get an error.

In most cases, importing doesn't affect performance to any discernible degree, but it is often easier for maintenance to list exactly the symbols you want to import. If you have many use statements, it's easy to search for which module gave you a particular symbol.

But it is worth mentioning that a few peculiar modules (if I remember correctly, POSIX and/or CGI) have quite many symbols, and only compile the routines to be exported as requested. In this case, it can make a noticeable difference in start-up time if you import all routines.


Comment on Re: Difference between use Module::Name and use Module::Name qw /method1 method2/
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-12-26 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls