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?
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";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With