perl.beginners
[Top] [All Lists]

Re: Re: Re: @INC and cross-platform path usage

Subject: Re: Re: Re: @INC and cross-platform path usage
From: Jenda Krynicky
Date: Wed, 02 Jul 2008 13:12:54 +0200
Newsgroups: perl.beginners

From: "Amit Saxena" <learn.tech123@xxxxxxxxx>
> I still doubt whether
> 
> * unshift (@INC,$librarydir);*
> 
> works or not.
> 
> To the best I have read the articles and tutorials, @INC can't be updated in
> this way.

Then you've read them wrong. Of course you can use unshift() on @INC, 
you just have to make sure it happens soon enough. Which means it 
either has to be within a module either in import() or outside any 
subroutines or in a BEGIN{} block.

You simply have to make sure the statement RUNS before the use 
statement that depends on that directory COMPILES. Which is quite 
possible in Perl.

Eg.

#!perl
BEGIN {
  do some computation regarding $librarydir
  unshift (@INC,$librarydir);
}
use My::Own::Library;
...
__END_

or

#!perl
use SetUpLibraryDir; 
 # this module must be in the default @INC directories
use My::Own::Library;
...
__END_

where in SetUpLibraryDir.pm you might have just

  do some computation regarding $librarydir
  unshift (@INC,$librarydir);

  1;

Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


<Prev in Thread] Current Thread [Next in Thread>