user740521 user740521 - 2 months ago 8
Perl Question

Perl script can't locate include file when run from the system command

I have the following files.

a.pl

#!/usr/bin/perl
system('perl b.pl');

b.pl

print `cwd`;
require "conf/cf.pl";

cf.pl

$var = "val";
1;


And this is the directory set-up.

testdir/a.pl
testdir/b.pl
testdir/conf/cf.pl


I am in the directory testdir and run the command:

perl a.pl


This fails with

testdir
Can't locate conf/cf.pl in @INC...


Why can't it find that include file even though the current directory is correct?

This is on Kali Linux.

Answer

Which version of Perl are you using? There are things afoot to remove the current directory from @INC as a response to CVE-2016-1238. Try printing the value of @INC in each part of the chain to verify this.

To change this, you can deliberately add a directory to @INC.