[Columbus-pm] use lib and BEGIN @INC

Len Jaffe lenjaffe at jaffesystems.com
Fri Nov 12 14:57:28 PST 2010


On Fri, Nov 12, 2010 at 5:04 PM, Jonathan Hogue <jon at hogue.org> wrote:

> no, BEGIN runs at compile-time too.
>
> found my error... it wasn't related to the difference between the 2 at
> all... I had a trailing space in my path name when doing the latter.
>
> On Fri, Nov 12, 2010 at 5:02 PM, Len Jaffe <lenjaffe at jaffesystems.com>
> wrote:
> > use executes at compile-time, BEGIN runs after compilation, so you're
> > use-ing a module before you unshift its home to @INC.
> >
> > On Fri, Nov 12, 2010 at 4:45 PM, Jonathan Hogue <jon at hogue.org> wrote:
> >>
> >> What's the difference between
> >> use lib "/somepath";
> >> and
> >> BEGIN{ unshift( @INC, "/somepath" ) };
> >>
> >> When I do
> >> use DQ::SomeModule after the "use lib" approach, it works, but not
> >> after the BEGIN block, even though when I dump @INC, it shows the
> >> /somepath for both scenarios
> >
> > use executes at compile-time, BEGIN runs after compilation, so you're
> > use-ing a module before you unshift its home to @INC.
> >
> > By the time you dump, the @INC arrays look the same, but the got there by
> a
> > temporally different execution path
>



BEGIN runs after use.


main.pl
----------------

use Foo;
use 5.10.1;

BEGIN {
   say "main BEGIN";
}
--------


Foo.pm
-----------------------
package Foo;

use 5.10.1;

say "I am Foo";

1;
----------------------------

C:\perlstuff> perl main.pl
I am Foo
main BEGIN

C:\perlstuff>


the use executes before the BEGIN.







-- 
lenjaffe at jaffesystems.com   614-404-4214
Scoutmaster Troop 156 - www.bsatroop156.org
Proprietor: http://www.theycomewithcheese.com/ - An Homage to Fromage
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/columbus-pm/attachments/20101112/dd06343c/attachment.html>


More information about the Columbus-pm mailing list