I just installed Centos 8 on my server to migrate everything from Centos 7 to Centos 8. I make use a many custom written Perl CGI scripts that is used with the web server (Apache). These scripts have many .pm modules that they use. To include the modules from the .cgi script files ‘use’ is being used. For example:
/cgi-bin/somescript.cgi
#!/usr/bin/perl
use some_module;
In the example above some_module.pm is located inside /cgi-bin but when I try to run http://192.168.0.1/cgi-bin/somescript.cgi the following error occurs:
Can’t locate some_module.pm in @INC
This used to work flawlessly in Centos 7 but not in Centos 8. How would I go about to get Perl to look inside the current directory for the modules like it used to in earlier versions of Centos when the .cgi script files are executed?
2
Answers
As @choroba indicated in their comment,
.
is no longer in the default list of paths in@INC
. You can add a library path withuse lib
:use lib '/cgi-bin';
or
use lib '/var/www/cgi-bin';
(whichever more accurately reflects your libraries’ location.)
Centos 7 includes Perl 5.16.3. Centos 8 includes Perl 5.26.3. That’s a difference of five major versions (5.18, 5.20, 5.22, 5.24 and 5.26). Before making such a big leap in versions, it is wise to read the relevant perldelta manual pages.
In perl5260delta, you will find this:
So by updating to this version, you have broken your code.
The simple (but ill-advised) fix that brings back the previous behaviour is to add this near the top of your file (before it tries to load the libraries):
However, this isn’t recommended as it breaks when your code is not run from the directory containing your code. The better fix has always been to add a library path that is relative to the directory containing the main program. That might look like this: