How can my Perl script find its module in the same directory?

后端 未结 9 1044
执念已碎
执念已碎 2020-12-23 19:26

I recently wrote a new Perl script to kill processes based on either process name / user name and extended it using Classes so that I could reuse the process code in other p

9条回答
  •  甜味超标
    2020-12-23 19:54

    From perlfaq8, which answers "How do I add a directory to my include path (@INC) at runtime?". There are several other answers for questions around this issue too.


    How do I add a directory to my include path (@INC) at runtime?

    Here are the suggested ways of modifying your include path, including environment variables, run-time switches, and in-code statements:

    the PERLLIB environment variable

    $ export PERLLIB=/path/to/my/dir
    $ perl program.pl
    

    the PERL5LIB environment variable

    $ export PERL5LIB=/path/to/my/dir
    $ perl program.pl
    

    the perl -Idir command line flag

    $ perl -I/path/to/my/dir program.pl
    

    the use lib pragma:

    use lib "$ENV{HOME}/myown_perllib";
    

    The last is particularly useful because it knows about machine dependent architectures. The lib.pm pragmatic module was first included with the 5.002 release of Perl.

提交回复
热议问题