Doesn’t Perl include current directory in @INC by default?

Perl doesn’t search the current directory for modules or the script’s directory for modules, at least not anymore. The current directory was removed from @INC in 5.26 for security reasons.

However, any code that relies on the current directory being in @INC was buggy far before 5.26. Code that did so, like yours, incorrectly used the current directory as a proxy for the script’s directory. That assumption is often incorrect.

To tell Perl to look in the script’s directory for modules, use the following:

use FindBin 1.51 qw( $RealBin );
use lib $RealBin;

or

use Cwd qw( abs_path );
use File::Basename qw( dirname );
use lib dirname(abs_path($0));

Leave a Comment