0
votes

I have one .pm and .pl file in the same location. When i execute the file, it works fine. When i keep .pm and .pl file in different location, I get this error. How to handle this, pls share your input. Appreciate your help!

[sjothili@localhost script]$ perl fapatch-prereq.pl Can't locate Fapatching.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at fapatch-prereq.pl line 3.

[sjothili@localhost Apr3]$ pwd
/scratch/sjothili/perl/Apr3

enter code herecat Fapatching.pm

#!/usr/bin/perl

package Fapatching;

sub doSystemCommand
{
     $systemCommand = $_[0];

    print LOG "$0: Executing [$systemCommand] \n";
     $returnCode = system( $systemCommand );

    if ( $returnCode != 0 )
    {
        die "Failed executing [$systemCommand]\n";
                exit 0;
    }
}



1;
 cat fapatch-prereq.pl
#!/usr/bin/perl
require Fapatching;
Fapatching::doSystemCommand("pwd");

[sjothili@localhost Apr3]$ perl fapatch-prereq.pl /scratch/sjothili/perl/Apr3

[sjothili@localhost script]$ cd ..
[sjothili@localhost Apr3]$ pwd
/scratch/sjothili/perl/Apr3
[sjothili@localhost Apr3]$ cd script/
[sjothili@localhost script]$ ls
fapatch-prereq.pl
`enter code here`[sjothili@localhost script]$ perl fapatch-prereq.pl
Can't locate Fapatching.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at fapatch-prereq.pl line 3.
2
Why can't you load in the primary library lib folder?ssr1012

2 Answers

3
votes

You didn't specify where Fapatching.pm is located, so let's say you have the following (pretty common) directory structure:

$project_home/bin/fapatch-prereq.pl
$project_home/lib/Fapatching.pm

You can solve this by adding the following to the script:

use FindBin qw( $RealBin );
use lib "$RealBin/../lib";

Adjust to your needs.

2
votes

Adding a use lib statement to the script will add the directory to @INC for that specific script. Regardless who and in what environment runs it. Referred from here.

use lib '/folder1/folder2/package';
use Fapatching;

Thanks to Author: Gabor Szabo. I am not recommeded however I referred here.