You can also set the environment variable PERL5LIB to whatever directory
that contains your
custom library files.

Regards,
Amit Saxena

On Tue, Jul 1, 2008 at 6:32 PM, Gunnar Hjalmarsson <[EMAIL PROTECTED]>
wrote:

> Tobias Eichner wrote:
>
>> I have created a Perl library that I want to use with my programs
>> (via require). However the Perl library should be placed at a
>> sub-folder of the working directory (the place where the program
>> runs).
>>
>> For example:
>>
>> /my/custom/path/ is the location of the program.
>> /my/custom/path/libraries/ is the location where I want to place my
>> Perl libraries in.
>>
>> How can I implement this considering that my Perl program will run on
>> different platforms with different ways of writing paths ?
>>
>> Would it work to use require "./libraries/mylib.pl" on all platforms
>> (*nix, Windows, Mac, something else) ? I don't think so. Not sure if
>> paths can be used overall with require (not tried it yet).
>>
>> My idea would be to use the standard module File::Spec to add the
>> path to my libraries to @INC. For example:
>>
>> my $mylibpath = File::Spec->rel2abs("libraries/");
>> unshift(@INC,$mylibpath);
>>
>> Is this a cross-platform compatible way ? Or is there a better
>> solution ?
>>
>
> Both those methods assume that the path to the directory where the program
> resides equals the current working directory. That's often the case, but not
> always.
>
> Some would suggest the use of the FindBin module. It does the right thing,
> but unfortunately it is known to be buggy.
>
> In a similar case I chose to simply say
>
>    use lib 'libraries';
>
> and tell the users to manually change 'libraries' to the full path when
> necessary.
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

Reply via email to