Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Difference between 'use' and 'require'

by broquaint (Abbot)
on Dec 07, 2004 at 09:57 UTC ( [id://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 (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://412870]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found