Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Difference between 'use' and 'require'

by gothic_mallard (Pilgrim)
on Dec 07, 2004 at 09:39 UTC ( #412868=note: print w/replies, xml ) Need Help??


in reply to Re^2: Difference between 'use' and 'require'
in thread Difference between 'use' and 'require'

Ah yes, forgot that one :)

A use anywhere in the code will be evaluated when the code is run compiled, but require - import's can only get evaluated when encoutered - good for when you want one module or another but both have quite a large initialisation overhead which means you only want the one you need.

update D'oh, sorry, meant compile not run.

--- Jay

All code is untested unless otherwise stated.
All opinions expressed are my own and are intended as guidance, not gospel; please treat what I say as such and as Abigail said Think for yourself.
If in doubt ask.

Replies are listed 'Best First'.
Re^4: Difference between 'use' and 'require'
by bart (Canon) on Dec 07, 2004 at 10:28 UTC
    No, you can require+import modules any time you like, even at runtime. use is at compile time.

    The reason the latter matters is because modules can change the way the rest of the source is compiled, think of integer, prototyped imported subs, or even plain subs, and constants.

    And that will not work at runtime, because it's too late.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-08-17 01:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?