MrSnrub has asked for the wisdom of the Perl Monks concerning the following question:

When I'm at my Linux prompt I write in the following command:

perl -e 'print join("\n", @INC);'

...I get a set of paths.

However, when I edit a .pl file and type in use [module]; in that file, I get an error at my prompt that says Can't locate [module].pm in @INC (@INC contains: [...]) but the problem is the list of paths that follow are entirely different from the ones I got when I did the perl -e 'print join("\n", @INC);' command. Why am I getting two sets of results, and which one is correct?

Replies are listed 'Best First'.
Re: Why am I getting two different results for my @INC variable?
by tinita (Parson) on Nov 29, 2011 at 00:45 UTC
    It would be a great help if you actually posted the results you are getting.
    My guess is: the perl you call from commandline is a different one than the one of the perl script.
    How do you call the perl script? ./script.pl or perl script.pl?
    What does the command which perl output?
    What's the shebang (first line) of the script?
Re: Why am I getting two different results for my @INC variable?
by chromatic (Archbishop) on Nov 29, 2011 at 00:45 UTC

    Does your .pl file contain any use lib '...'; lines? Does its shebang line point to the same perl binary as which perl reports on the command line? Does it include any switches such as -I or -T?


    Improve your skills with Modern Perl: the free book.

Re: Why am I getting two different results for my @INC variable?
by toolic (Bishop) on Nov 29, 2011 at 00:52 UTC
Re: Why am I getting two different results for my @INC variable?
by MrSnrub (Beadle) on Nov 29, 2011 at 00:58 UTC
    When I do a which perl I get /usr/bin/perl, but the shebang in my code is different. I change my code to /usr/bin/perl, and now I get correct results. Huh.

      This makes sense. From the command prompt you would be using the same perl as found from which perl. If the shebang is different, find out why. The system perl is not necessarily the one your application is expecting, nor is the one your shebang line pointing to necessarily appropriate for system use.

      For my $day_job, I ignore the system perl entirely, and build or include the perl installation as part of my application (or set of applications). Changes to the system then have less of a chance of impacting my applications.

      --MidLifeXis