|Pathologically Eclectic Rubbish Lister
Re^3: loading modules using 'use'by Taulmarill (Deacon)
|on Jul 01, 2010 at 12:04 UTC
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:
So far, so simple. Now, what perl is doing here, can also be written like this:
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.
The header is not printed out, if we run this. Activating the warnings gives a few hints to what is going on.
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