Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Difference between 'use' and 'require'

by broquaint (Abbot)
on Dec 07, 2004 at 09:57 UTC ( #412870=note: print w/ replies, xml ) Need Help??


in reply to Difference between 'use' and 'require'

The differences are many and often subtle:

  • use only expects a bareword, require can take a bareword or an expression
  • use is evaluated at compile-time, require at run-time
  • use implicitly calls the import method of the module being loaded, require does not
  • use excepts arguments in addition to the bareword (to be passed to import), require does not
  • use does not behave like a function (i.e can't be called with parens, can't be used in an expression, etc), whereas require does
So they behave differently but achieve the same goal. Then there's a list of cultural differences in addition to the technical differences, but they're not so hard and fast.
HTH

_________
broquaint


Comment on Re: Difference between 'use' and 'require'
Replies are listed 'Best First'.
Re^2: Difference between 'use' and 'require'
by ikegami (Pope) on Dec 07, 2004 at 15:01 UTC
    use implicitly calls the import method of the module being loaded, require does not

    That's optional. Adding empty parens (as in use Socket ();) prevents import from being called.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (20)
As of 2015-07-30 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls