Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell perl the path for a module?

I use a perl module file in my perl script:

printtab.pl

use Table;

Table.pm is present in the same directory as printtab.pl, so as long as I am executing printtab from the directory, it executes fine.

But If I execute it from some other place, for example, using a cronjob, I get an error mentioning that the module is not found in @INC.

What is the correct way to resolve this?

I tried

push @INC, "/path/Table.pm";

but it does not work. Can you tell me why?

I found about use lib and it works correctly

use lib "/path";

Is use lib the best method in such a situation?

like image 579
Lazer Avatar asked Dec 01 '22 02:12

Lazer


1 Answers

use lib is a good option. But is you place your modules in the same directory as your programs (or in a sub-directory relative to the one containing your programs), you could use use FindBin; like:

use FindBin;
use lib "$FindBin::Bin/../lib";
like image 110
pavel Avatar answered Dec 05 '22 00:12

pavel