Perl Can't Locate File.pl in @INC
Overview
Section titled “Overview”In Perl 5.26 and later, the current directory (.) is removed from @INC by default for security reasons. As a result code such as the following will no longer work:
require "File.pl";Error message
Section titled “Error message”The error message you’ll see is as follows:
Can't locate File.pl in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at /home/username/public_html/cgi-bin/my_script.pl line 20.Solution
Section titled “Solution”To include a module from the same directory as your script, the two easiest approaches are:
- Use the
FindBinmodule:
use FindBin; use lib $FindBin::RealBin;Place that before your require statements.
- Use explicit path for the file
require "./File.pl";