in reply to Re: Re: Dynamic "use lib"
in thread Dynamic "use lib"

Now, that makes absolutely no sense. BEGIN blocks are supposed to happen AT compile-time, meaning they happen simultaneous with the use statements.

Or, does each BEGIN-block get its own BEGIN-CHECK-INIT-END sequence?

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

Replies are listed 'Best First'.
Re: Re: Re: Re: Dynamic "use lib"
by samtregar (Abbot) on May 21, 2004 at 17:33 UTC
    You're missing the point. The 'use' statement does its thing at compile-time. That means that as soon as Perl compiles a 'use lib' it affects @INC. That's as true inside a BEGIN as it is outside a BEGIN. Here let me demonstrate:

    BEGIN { if (@INC) { use lib '/foo'; } else { use lib '/bar'; } } print "INC IS: @INC\n";

    Running this code you can see that the 'if' did not effect the 'use' statements. That's because 'if' is a run-time operator and 'use' is a compile-time statement. See:

    $ perl begin.pl INC IS: /bar /foo /usr/local/lib/perl5/5.6.1/i686-linux /usr/local/lib +/perl5/5.6.1 /usr/local/lib/perl5/site_perl/5.6.1/i686-linux /usr/loc +al/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .

    -sam