On Thursday 01 May 2008 7:06 am, André Warnier wrote:
> Mark Stosberg wrote:
> >> +    my $dir = dirname(__FILE__);
> >> +    use lib $dir.'/../config';
> >> +    use lib $dir.'/../perllib';
> >
> > Actually, for some reason that syntax didn't work either, but this did
> > work on my modperl-startup.pl:
> >
> >  use lib dirname(__FILE__).'/../config';
> >  use lib dirname(__FILE__).'/../perllib';
> >
> >     Mark
>
> this is a question to the perl gurus here :
>
> In the first part above (what does not work), is it not because the "use
> lib" instructions are actually "executed" at the perl *compile* time, at
> which time the $dir variable does not have any value yet ?

Yes.

Crazier yet, if you do it as:

    my $dir;
    BEGIN { $dir=dirname(__FILE__) };
    use lib $dir.'/../config';
    use lib $dir.'/../perllib';

and put the assignment in a BEGIN block, it still doesn't work (at least, I 
haven't been able to get it to work).

I cheated, and when I needed this idiom I created a module that exported the 
value, and which assigned it in its "import()" method.  Gave me something 
like:

  use FindMe qw($ME);
  use lib $ME.'/../config';
  use lib $ME.'/../perllib';

and that worked fine.  The "import()" routine gets called and sets the value 
before its used in the following lines.

Now... why the BEGIN block doesn't do it, I've no idea and didn't poke too 
much farther into it to figure out why.

-- 
Graham TerMarsch
Howling Frog Internet Development, Inc.

Reply via email to