Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling perl module from current directory

I need to test a perl script in a remote server. I tried running it but i got the error

Can't locate Date/Manip.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl . 

So I downloaded the DateManip.pm file and tried to copy it in one of the locations mentioned. But I don't have permission to copy the file in any of these places. Is there a way I can have this *.pm file in my own directory and call it from there or do I HAVE to put it in one of those locations?

like image 346
sfactor Avatar asked Sep 20 '26 12:09

sfactor


2 Answers

The correct way to do this is install DateManip.pm obviously, however if you cannot for some reason do that, then you can copy the module to any directory you have write permissions to and modify the perl script to include the following:

 use FindBin qw($Bin);
 use lib "$Bin/<relative_path_to_module>";

<relative_path_to_module> is the relative path to the directory where DateManip.pm is located. So if the relative path to the module is ../lib, you would have

use FindBin qw($Bin);
use lib "$Bin/../lib";
like image 135
ennuikiller Avatar answered Sep 23 '26 01:09

ennuikiller


By default Perl will also look in the current directory (where it is being run) for a module. So the following will work:

./your_program.pl     <= "use DateManip"
./DateManip.pm

If the module was called Date::Manip then the structure would need to be like this:

./your_program.pl     <= "use Date::Manip"
./Date/
./Date/Manip.pm
like image 27
draegtun Avatar answered Sep 23 '26 00:09

draegtun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!