-3

I am a new guy learning perl and working as it goes. I am really stuck at this point, been working on this thing for past 4 Hr without any results.

I am using a bunch of custom Modules inside a directory and then I got a ticket to implement a new KnowledgeBase and so I added a new module in the Moduledirectory. After adding it, when I try to access MyModule it does not work at all. I get

Can't locate FolderName/MyModuleName.pm in @INC 

Can someone please help me. It is getting really annoying. I have tried to restart apache server, but still the same error shows up.

I also tried to just compile my module, but I get the same error except the name of the module is different it is the one that I am calling/using in MyModule.

Please let me know if you can help me. Thanks in advance.

Edit: Adding more details, the exact error that I am getting (with line breaks for readability) is:

Can't locate Net2Net/KnowledgeBase.pm in @INC (@INC contains:
    (DOCUMENT_ROOT)/bin 
    /usr/local/lib/perl5/5.8.8/sun4-solaris
    /usr/local/lib/perl5/5.8.8
    /usr/local/lib/perl5/site_perl/5.8.8/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.8.8
    /usr/local/lib/perl5/site_perl
    .
) at /data1/web/intradev.com-80/docs/gss/kb/ajax-kb-update.cgi line 6.
BEGIN failed--compilation aborted at /data1/web/intradev.com-80/docs/gss/kb/ajax-kb-update.cgi line 6.
ikegami
  • 367,544
  • 15
  • 269
  • 518
Parik Tiwari
  • 1,525
  • 1
  • 12
  • 19
  • 1
    What's the rest of the error message? What's the full path to the module. Does the user as which the apache process is running have sufficient permission to those files and the directories leading up to the file? – ikegami Sep 25 '12 at 02:14
  • I have added the full error message, the full path in included in the error message. I double checked that not only the files but the folder containing the files has the write/execute permission for the user(https) running apache. – Parik Tiwari Sep 25 '12 at 18:08
  • What's the full path to `KnowledgeBase.pm`? And does that actually say "(DOCUMENT_ROOT)", or is that you hiding sensitive data? (It's fine if you did, but I need to know which one it is. It's better to hide sensitive data by changing the sensitive word for another.) – ikegami Sep 25 '12 at 18:17
  • no it is not a replacement, the website is hosted on a Sun server and the directory structure is in that way and the original path to file is /data1/web/intradev.com-80/docs/bin/Net2Net/KnowledgeBase.pm – Parik Tiwari Sep 25 '12 at 18:22

2 Answers2

7

The error message says it all...

Where are your custom modules installed?

Perl uses an array called @INC to track directories for searching for Perl modules. If you type in perl -V at the command line, you'll see where your default list of @INC directories. You can put your modules in one of the directories in the @INC list. You can also add directories to @INC with the use lib; pragma. This needs to be in your Perl source code.

Most @INC lists include the current directory, so you can usually stick modules in there. However, is running as a CGI script in Apache or perl_mod? Best thing to do is to use the use Cwd; module to see what the current directory is. CGI might be removing certain environment variables as a security measure.

One more thing. If a Perl module is Foo::Bar, the module is Foo/Bar.pm somewhere under one of the directories under the @INC directory list. If it's Foo::Bar::Foom, it's refering to the module Foo/Bar/Foom.pm. Some people simply copy the module without the directory.

David W.
  • 105,218
  • 39
  • 216
  • 337
1

The file is located at

/data1/web/intradev.com-80/docs/bin/Net2Net/KnowledgeBase.pm 

But Perl searches the following locations (assuming cwd is /, which is likely for an CGI under apache):

/(DOCUMENT_ROOT)/bin/Net2Net/KnowledgeBase.pm 
/usr/local/lib/perl5/5.8.8/sun4-solaris/Net2Net/KnowledgeBase.pm 
/usr/local/lib/perl5/5.8.8/Net2Net/KnowledgeBase.pm 
/usr/local/lib/perl5/site_perl/5.8.8/sun4-solaris/Net2Net/KnowledgeBase.pm 
/usr/local/lib/perl5/site_perl/5.8.8/Net2Net/KnowledgeBase.pm 
/usr/local/lib/perl5/site_perl/Net2Net/KnowledgeBase.pm 
/Net2Net/KnowledgeBase.pm

As such, Perl cannot find it. You have to tell it to look in

/data1/web/intradev.com-80/docs/bin

You can do that by adding

use lib '/data1/web/intradev.com-80/docs/bin';

to your .cgi. (Other ways include using the -I command line option and env var PERL5LIB. See perlrun.) It looks like someone tried to do that (or equivalent), but messed up by doing (the equivalent of)

use lib '(DOCUMENT_ROOT)/bin';   # Wrong!

The following would also work if you want to use a relative path:

use Cwd            qw( realpath );
use File::Basename qw( dirname );

use lib dirname(realpath($0)).'/../../bin';
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • Thank you so much for your help, when I replaced use lib '(DOCUMENT_ROOT)/bin'; with use lib '/data1/web/intradev.com-80/docs/bin'; it worked perfectly for me. – Parik Tiwari Sep 26 '12 at 18:12
  • 1
    @Parikshit Tiwari, The web server **might** provide the document root as an env var. If so, you could do `use lib "$ENV{DOCUMENT_ROOT}/bin";` – ikegami Sep 26 '12 at 18:16