<br><br><div class="gmail_quote">On Fri, Nov 12, 2010 at 5:04 PM, Jonathan Hogue <span dir="ltr"><<a href="mailto:jon@hogue.org">jon@hogue.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
no, BEGIN runs at compile-time too.<br>
<br>
found my error... it wasn't related to the difference between the 2 at<br>
all... I had a trailing space in my path name when doing the latter.<br>
<div><div></div><div class="h5"><br>
On Fri, Nov 12, 2010 at 5:02 PM, Len Jaffe <<a href="mailto:lenjaffe@jaffesystems.com">lenjaffe@jaffesystems.com</a>> wrote:<br>
> use executes at compile-time, BEGIN runs after compilation, so you're<br>
> use-ing a module before you unshift its home to @INC.<br>
><br>
> On Fri, Nov 12, 2010 at 4:45 PM, Jonathan Hogue <<a href="mailto:jon@hogue.org">jon@hogue.org</a>> wrote:<br>
>><br>
>> What's the difference between<br>
>> use lib "/somepath";<br>
>> and<br>
>> BEGIN{ unshift( @INC, "/somepath" ) };<br>
>><br>
>> When I do<br>
>> use DQ::SomeModule after the "use lib" approach, it works, but not<br>
>> after the BEGIN block, even though when I dump @INC, it shows the<br>
>> /somepath for both scenarios<br>
><br>
> use executes at compile-time, BEGIN runs after compilation, so you're<br>
> use-ing a module before you unshift its home to @INC.<br>
><br>
> By the time you dump, the @INC arrays look the same, but the got there by a<br>
> temporally different execution path<br></div></div></blockquote></div><br clear="all"><br><div><br></div><div>BEGIN runs after use.</div><div><br></div><div><br></div><div><a href="http://main.pl">main.pl</a></div><div>
----------------</div><div><div><br></div><div>use Foo;</div><div>use 5.10.1;</div><div><br></div><div>BEGIN {</div><div> say "main BEGIN";</div><div>}</div></div><div>--------</div><div><br></div><div><br></div>
<div>Foo.pm</div><div>-----------------------</div><div><div>package Foo;</div><div><br></div><div>use 5.10.1;</div><div><br></div><div>say "I am Foo";</div><div><br></div><div>1;</div></div><div>----------------------------</div>
<div><br></div><div><div>C:\perlstuff> perl <a href="http://main.pl">main.pl</a></div><div>I am Foo</div><div>main BEGIN</div><div><br></div><div>C:\perlstuff></div></div><div><br></div><div><br></div><div>the use executes before the BEGIN.</div>
<div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br>-- <br><a href="mailto:lenjaffe@jaffesystems.com">lenjaffe@jaffesystems.com</a> 614-404-4214<br>Scoutmaster Troop 156 - <a href="http://www.bsatroop156.org">www.bsatroop156.org</a><br>
Proprietor: <a href="http://www.theycomewithcheese.com/">http://www.theycomewithcheese.com/</a> - An Homage to Fromage<br>
</div>