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

后端 未结 9 1059
执念已碎
执念已碎 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 20:04

    Besides the already stated solutions:

    1. use FindBin / lib
    2. Perl Faq 8 How do I add a directory to my include path (@INC) at runtime?

    'The simplest approach' (™) that I use while dev/testing a module prior to deploying it (in /usr/local/lib/site_perl/ or elsewhere in @INC) is to modify @INC before loading the module as follows:

    #!/usr/bin/perl
    use strict;
    use warnings;
    # Modify @INC prior to module loading.
    BEGIN { unshift @INC, '.'; }
    use YourModuleInCWD;
    

    (Add current working directory to @INC? - PerlMonks)

提交回复
热议问题