Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1082723]
help
Chatterbox?
[holli]: there probably is some nodelet hack that lets you use markdown :)
[LanX]: a) well ... you can use the xml-version to get the original code w/o need of reverse engineering
[moritz]: yes, and that's the next problem: there are piles of workarounds, but not solution, no visible progress
[LanX]: b) you cahnge my wikisyntax to support markdown and stay PM compatible
[holli]: see moritz, the , how do i put it, robust charme of this site is what separates the wheat from the chaff ^^
[LanX]: I'm willing to improve the code, but we have a götterdämmerung at the moment, Corion is the only active god for some time now
[moritz]: and everybody is like "if you just copy 250 lines of ugly JS into your free nodelet, and happent to know about it, there is a 40% that this workaround kinda works, sometimes"
[moritz]: ... "so there is no need to do anything"
[LanX]: and the code is a bit of a mess
[LanX]: moritz, no ... jsut copy one line of my code

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2017-11-20 19:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (291 votes). Check out past polls.

    Notices?