Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

G'day ghosh123,

In the use documentation, you'll see:

It is exactly equivalent to

BEGIN { require Module; Module->import( LIST ); }

except that Module must be a bareword. The importation can be made conditional by using the if module.

So, if you had to use require, you could still get the compile time checks with:

BEGIN { require Module; }

However, reading a bit further down the use documentation, you'll see that this is exactly equivalent to

use Module ();

So, unless you're unable to specify a bareword for Module (see this post of mine from a few days ago for an example), or you have a particular need to load Module at runtime (e.g. your point #4 scenario [although see below]), there's really no reason not to use use.

Finally, regarding the points you made:

  1. Correct.
  2. Correct.
  3. The "control is passed to that file at run-time" part doesn't sound right at all. If, after reading the documentation I've provided links to, you still believe this is correct, please clarify what you mean (perhaps I'm missing your intent).
  4. In that particular scenario, you'd probably need to weigh up whether you want to avoid an initialisation delay at the expense of (conditionally) having the same delay at some point in the middle of the program. There are situations where modules are loaded conditionally, using require, that have nothing to do with initialisation delays (as an example, see the File::Spec source code).

-- Ken


In reply to Re: What are the advantages or disadvantages of "require" over "use" by kcott
in thread What are the advantages or disadvantages of "require" over "use" by ghosh123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (20)
    As of 2014-07-24 14:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (160 votes), past polls