in reply to Re: Breaking a script into smaller files
in thread Breaking a script into smaller files

How does using a BEGIN block (as opposed to use lib) help you not "loose track of what module uses the modified search path and what module doesn't"?

And isn't @INC global, so changing it first in my main script will affect all modules?

  • Comment on Re: Re: Breaking a script into smaller files

Replies are listed 'Best First'.
Re: Re: Re: Breaking a script into smaller files
by chromatic (Archbishop) on Nov 13, 2001 at 05:36 UTC
    BEGIN blocks fire at compile time, just like use statements. (Camel 3 points out that "use" is just a fancy BEGIN block. See page 465.) They also go in order, top to bottom.

    The point of changing @INC at compile time is to make sure that the new paths are there when modules are loaded. If you don't do that at compile time (with either BEGIN or use lib), it won't affect any of your modules.

    Can I say "compile time" enough?

    Update: There's no effective difference between use lib and the BEGIN block (with unshift), except that lib adds some architecture-dependent directories, if they exist. I was only addressing the "@INC is global" question. (Short answer: it is, but the important thing is *when* it is changed.)

      I'm quite aware that BEGIN blocks fire at compile time. But so does use lib. My question is: why does Biker say that BEGIN is better? And what did he mean by "..loose[sic] track of what module uses the modified search path and what module doesn't"?

      —John