I'm unsure if i got exactly what you are asking, but let me give you some examples. Let's start with a fairly common thing:

use CGI qw/:standard/; print header;

So far, so simple. Now, what perl is doing here, can also be written like this:

BEGIN { require CGI; CGI->import( ':standard' ); } print header;

You'll notice, this gives you the same output as the first example. Now let's see what happens, when we don't use the BEGIN block.

require CGI; CGI->import( ':standard' ); print header;

The header is not printed out, if we run this. Activating the warnings gives a few hints to what is going on.

Unquoted string "header" may clash with future reserved word at test.p +l line 12. Name "main::header" used only once: possible typo at test.pl line 12. print() on unopened filehandle header at test.pl line 12.

Now what happened here?!? perl doesn't know how to handle header anymore, because at the compile time of the program, the subroutine is not yet known to perl. It gets imported at runtime, since require doesn't do anything at compile time, and perl thinks, handler is supposed to be a file handle.

Hope this cleared some thing up for you


In reply to Re^3: loading modules using 'use' by Taulmarill
in thread loading modules using 'use' by angshuman

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.