Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
Keep It Simple, Stupid
 
PerlMonks  

Re: When C<use Module;> *not* the same as C<require Module; import Module;>?

by etcshadow (Priest)
on Jan 08, 2005 at 21:12 UTC ( [id://420620]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to When C<use Module;> *not* the same as C<require Module; import Module;>?

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://420620]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.