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 ?

I would choose to put the library in the same directory as the program, and use
the fact that the current directory is the last entry in @INC so no additional
locations need to be specified.

I would also recommend that you write a conventional Perl module - a .pm file -
so that you can just write

  require mylib;

HTH,

Rob

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


Reply via email to