0

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.

melpomene
  • 84,125
  • 8
  • 85
  • 148
user740521
  • 1,175
  • 4
  • 12
  • 25
  • Why is that needed though? It works fine on every other version of linux I've tried. – user740521 Sep 29 '16 at 20:14
  • 2
    Seems like the current directory is missing from your `@INC`. Try add `use lib '.'` in`b.pl` or use `require` with an absolute path name. Note: You can also add the current directory to `@INC` by setting the environment variable `PERL5LIB`. – Håkon Hægland Sep 29 '16 at 20:30
  • @HåkonHægland: Adding `$FindBin::Bin` might be safer, as `cwd` can change. – choroba Sep 29 '16 at 20:33
  • @choroba Good point. See also [lib pragma does not work when script called with relative path](http://stackoverflow.com/q/35464832/2173773) – Håkon Hægland Sep 29 '16 at 20:37
  • What's the complete error message? – melpomene Sep 29 '16 at 21:21
  • I ended up just using the -I flag, I don't know why the current directory isn't included in @INC by default on this installation. – user740521 Sep 29 '16 at 21:34
  • 3
    @user740521 There were some changes very recently because of security issues with the current directory being in `@INC`. Your perl probably includes those changes. This will be standard in 5.26, so you shouldn't rely on `.` being in the default `@INC`. – ThisSuitIsBlackNot Sep 29 '16 at 21:41
  • I believe there are some distros in the past that omitted `.` from `@INC` too; red hat maybe? – ysth Sep 30 '16 at 01:21
  • 2
    You [shouldn't](http://stackoverflow.com/q/6376006/589924) be using `require` for `.pl` files; you should be using `do`. (Better solution: Change the `.pl` file into an actual module.) – ikegami Sep 30 '16 at 16:41

2 Answers2

3

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.

Community
  • 1
  • 1
brian d foy
  • 129,424
  • 31
  • 207
  • 592
-1

Maybe command 'cwd' is the problem. Do you have this command in your Linux? I'm assuming you're running this on linux. Anyway, try to change to 'pwd'.