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

Re: What are the advantages or disadvantages of "require" over "use"

by tobyink (Abbot)
on Apr 18, 2014 at 07:32 UTC ( #1082723=note: print w/ replies, xml ) Need Help??


in reply to What are the advantages or disadvantages of "require" over "use"

If a module has a compile-time effect (exporters and pragmata), then use use. Otherwise (e.g. for OO modules), you can choose.

A good reason to go with require would be when loading a module that isn't always needed. Say you are writing a module that offers load_from_file and load_from_web functions. In this case you might want to require LWP::UserAgent (or HTTP::Tiny or whatever) inside the definition of load_from_web. That way, if the person using your module never needs to load anything from the web (they only ever load from files), they can avoid loading LWP::UserAgent at all.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name


Comment on Re: What are the advantages or disadvantages of "require" over "use"
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-12-20 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (95 votes), past polls