Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2015-10-10 09:32 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (255 votes), past polls