You've actually hit on the reason why use is automatically treated as a compile-time directive (i.e., wrapped in a BEGIN{...} block): it alters the parser's syntactic interpretation of code. Specifically, there are places where the same piece of code can have ambiguous syntactic interpretations, depending on whether or not certain symbols are known to be subroutines.

For example, take:

print foo;
If foo is already known by the perl parser to be a subroutine, it will interpret this as meaning:
print(foo());
However, if the interpreter does not know that foo is supposed to be a subroutine, then it will interpret foo to be the name of a file-handle (the indirect argument to print). This is all happening at compile-time (well, parse-time, really... but parse and compile happen together), so it doesn't matter whether or not foo is a subroutine at runtime... because the parser will have already decided that it was being used as the name of a filehandle, at runtime.
------------ :Wq Not an editor command: Wq

In reply to Re: When C<use Module;> *not* the same as C<require Module; import Module;>? by etcshadow
in thread When C<use Module;> *not* the same as C<require Module; import Module;>? by BrowserUk

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.