On Jul 22, 11:59 pm, [EMAIL PROTECTED] (Chris Pax) wrote:
> I know that if i use: use lib "/path/to/dir" works. but when I try to
> use a variable it does not work.
> here is my code:
> @dirs = split /\// , $0;
> delete $dirs[-1];
> my $runningDir = join "/",@dirs;
> $runningDir.="/";
> use lib $runningDir;
>
> what I am trying to do with this coded is add the running directory of
> the file to the @INC at runtime.

No you're not.  You're trying to add it at compile time.  Adding it at
runtime would be much simpler:
push @INC, $runningDir;

Your problem is that if you do successfully add it at runtime, that's
already too late for anything you wanted to "use" at compile time.  So
your two options are to:
1) "use" the other modules at runtime, after you've modified @INC
push @INC, $runningDir;
require OtherModule;
OtherModule->import;

2) modify @INC at compile time

For the life of me, I don't know why no one has referred you to the
FAQ yet.

perldoc -q directory
     How do I add the directory my program lives in to the
     module/library search path?

         use FindBin;
         use lib "$FindBin::Bin";
         use your_own_modules;

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to