Reputation: 69
I'm trying to add the HTML::Entities module path to @INC
. I did export PERL5LIB=/mypath/HTML/
followed by source ~/.bashrc
. That path is reflected in PERL5LIB
, but not in @INC
. Is there an additional step that I'm missing?
I'm using perl 5.26.2 on CentOS6.5
Edit:
I (wrongly) assumed that my path wasn't being added to @INC because when I run my perl script I get
Can't locate HTML/Entities.pm in @INC (you may need to install the HTML::Entities module)
(@INC contains:
/home/hek/anaconda3/bin/aux/lib/perl5
/home/hek/anaconda3/lib/site_perl/5.26.2/x86_64-linux-thread-multi
/home/hek/anaconda3/lib/site_perl/5.26.2
/home/hek/anaconda3/lib/5.26.2/x86_64-linux-thread-multi
/home/hek/anaconda3/lib/5.26.2
)
(Line breaks added for readability)
But it does appear below
echo $PERL5LIB
/opt/rh/devtoolset-2/root//usr/lib64/perl5/vendor_perl:/opt/rh/devtoolset-2/root/usr/lib/perl5:/opt/rh/devtoolset-2/root//usr/share/perl5/vendor_perl:/opt/perl/lib/site_perl/5.14.2/x86_64-linux-thread-multi/HTML/
perl -e 'use Data::Dumper; print Dumper(\@INC), "\n"'
$VAR1 = [
'/opt/rh/devtoolset-2/root//usr/lib64/perl5/vendor_perl',
'/opt/rh/devtoolset-2/root/usr/lib/perl5',
'/opt/rh/devtoolset-2/root//usr/share/perl5/vendor_perl',
'/opt/perl/lib/site_perl/5.14.2/x86_64-linux-thread-multi/HTML/',
'/home/hek/anaconda3/lib/site_perl/5.26.2/x86_64-linux-thread-multi',
'/home/hek/anaconda3/lib/site_perl/5.26.2',
'/home/hek/anaconda3/lib/5.26.2/x86_64-linux-thread-multi',
'/home/hek/anaconda3/lib/5.26.2',
'.'
];
Why would there be this discrepency?
I do have multiple versions of perl installed, but which perl
returns the version that I need to use, ~/anaconda3/bin/perl
.
I tried changing the shebang in my script from #!/usr/bin/env perl
to #!/~/anaconda3/bin/perl
, but that didn't help.
Upvotes: 2
Views: 2196
Reputation: 66883
This is to summarize the problems and state what seems to be the simplest solution.
From the output of your test one-liner it is clear that a module installed under v5.14.2 is used in a program meant to run under v5.26.2. That is not good, even if it happens to work.
So install HTML::Entities
under the perl build that needs it, v5.26.2.
That also solves the problem you are asking about, since then you won't have to muck about with PERL5LIB
or anything else.
Further, the @INC
in your one-liner test clearly isn't loaded in your real run, just as you suspected. Possible reasons are given in ikegami's answer, as well as the solution, to use lib "...";
. But then you need to use the module version installed for v5.26.2, and once you installed it with that perl there'll actually be no need to specify extra library paths.
Finally, if you end up needing to add that path for some reason, leave off the HTML
(last) directory, as Shawn's answer indicates. With use HTML::Entities
the directory HTML
will be searched (for Entities.pm
file) and you only need to provide the directory that contains it.
Upvotes: 1
Reputation: 385764
Two possibilities:
PERL5LIB
env var wasn't set in the parent of the perl
process giving the error (e.g. you launched it from a web server), or-T
command line switch was provided to perl
process giving the error (since this causes PERL5LIB
to be ignored).In either case, you can use use lib
in the source instead of PERL5LIB
.
Upvotes: 2
Reputation: 52354
use HTML::Entities
looks for a file HTML/Entities.pm
in the directories in @INC
. No such path is found because it's looking for ones like /opt/perl/lib/site_perl/5.14.2/x86_64-linux-thread-multi/HTML/HTML/Entities.pm
.
Leave off the HTML/
part in the directory you're trying to add to the search path and you might have better luck.
Edit: There's still the version mismatch, but as long as the module is pure Perl without any XS components I don't think that will be a big problem. Still better to get it in the right path for the version of perl you're actually using. Do that and you shouldn't have to manipulate the search path at all.
Upvotes: 1