Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Difference between 'use' and 'require'

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


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

Any reason why you needed to post that in uber-print?

Anyhow, as far as I know you don't need to do a require AND a use as:

use MyModule;

.. is equivalent to:

require MyModule; import MyModule;

--- 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^2: Difference between 'use' and 'require'
by BUU (Prior) on Dec 07, 2004 at 09:33 UTC
    Except of course that use is evaluated at compile time where as require is evaluated at run time.

    And I second the question about the stupidly large font.

      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.

        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.

      @anonymous monk

      "the stupidly large font"

      if you really wanted the OP to post in a different format, you wd have made a suggestion using a civilized vocabulary or, as the first commenter did, ask a question in a civilized manner. but i suspect that you do not really care about the font the OP used. but wanted simply to vent some spleen. you are doing life in a very self-defeating manner. you are also befouling this site.
Re^2: Difference between 'use' and 'require'
by chb (Deacon) on Dec 07, 2004 at 09:38 UTC
    Not quite, perldoc -f use says use is equivalent to BEGIN { require Module; import Module LIST; }, meaning it is executed at compile time before everything else. This can bite if your modules depend on some initialisation written in normal code (outside a BEGIN-Block).
Re^2: Difference between 'use' and 'require'
by Anonymous Monk on May 04, 2012 at 06:28 UTC

    Please read the elaboration on working behind the scenes for "use" and "require" tags. http://www.perl.com/pub/2002/05/14/mod_perl.html

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (1)
As of 2022-08-09 23:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?