Problem with Perl tools.pm not found in @INC?

  • Thread starter Thread starter Dark Sky
  • Start date Start date
D

Dark Sky

Guest
I have the file X.cgi and tools.pm in the same folder, and I get this error when accessing X.cgi:

Can't locate tools.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl/5.8.8 /usr/local/lib/site_perl /usr/local/lib/perl/5.8.4 /usr/local/share/perl/5.8.4 .) at...
 
The most likely answer is that you're not executing the script from the directory where X.cgi and tools.pm are located. Having "." in @INC means searching in your current working directory, not in a directory where the script is located.

You can use the following snippet to verify what's your current working directory:
use Cwd;
print cwd, "\n";

To add directory where X.cgi is located to @INC, use this snippet before loading tools.pm:
use Cwd;
use File::Basename;
push @INC, dirname(Cwd::abs_path(__FILE__));

or simply:
push @INC, "/path/to/that/directory";
 
Back
Top