1
votes

Can't find lib in either /apps/cgi/kb or /apps/cgi, stopped at /usr/local/share/perl5/mylib.pm line 22. Compilation failed in require at www_kb_search_new_QA.pl line 4. BEGIN failed--compilation aborted at www_kb_search_new_QA.pl line 4.

Line 4 is "use mylib;"

if i comment "use mylib;" the script is executing normal and fine, but all my scripts are having "use mylib;" and its difficult to change all scripts. is there any procedure to update the mylib.pm file with all perl libraries??

Thanks, Kalyan

3
@Borodin can you please help with this question..... - kcnanduri

3 Answers

1
votes

Is there any procedure to update the mylib.pm file with all Perl libraries?

I thought I covered this in my answer to your previous question

There is nothing wrong with your installation of mylib. The issue is that it is looking for a directory called lib either in the same directory as your Perl source file or in the directory above

If it finds one of these two directories, it adds it to the list of locations that perl searches for modules included by any subsequent use statement. That is all it does. It is for use when you write your own Perl modules that need to be distributed along with the main Perl program file

From your previous question, one of your programs is /apps/cgi/kb/www_kb_search_new.pl, so mylib is looking for either

/apps/cgi/kb/lib

or

/apps/cgi/lib

and finding neither. That is the reason for the error message

Can't find lib in either /apps/cgi/kb or /apps/cgi

Since you say your program worked when you removed use mylib, it seems that your program doesn't use any modules in these locations. This may be true of all your programs, in which case the solution should be to delete the use mylib statement from all of them. This is easy to do with a simple shell command

Alternatively you could create one or other of these directories and leave it empty. That way mylib would execute correctly, find the lib directory, and add it to the search list, but no libraries would ever be loaded from there

I hope it's clear now?

0
votes

use mylib; is used to tell Perl where to find modules installed relative to the script. These are usually pure-Perl modules that are bundled with the script. It looks for ./lib and ../lib (relative to the location in which the script is located). Neither of those directories exist in your case.

The fact that the script expects there to be a lib directory that isn't there would suggest you have some files missing. If so, removing use mylib; would only make things worse.

If there's not suppose to be a lib directory, use mylib; shouldn't be used and should be removed (which can be done trivially using a one-liner[1]). Creating an empty lib directory in the directory in which your script is located would also stop your code from dying.


  1. find -name '*.pl' -type f -exec perl -i~ -pe's/^(?=use mylib;)/#/' {} +
-2
votes

'mylib.pm' is not in a directory listed in the PERL5LIB environment variable.

While testing, you can use the use lib 'path/to/module' work-around.

So, if you're testing a file myscript.pl that uses a module libs/mylib.pm you can add use lib 'libs/'; before the use mylib; command.

Longer term, you should place your module in a stable location, and a