I want to use an external library in the BEGIN block of a Perl script.
The first test which I did was to check whether my @INC is getting popullated if I push some values:
use strict;
use warnings;
BEGIN {
push @INC, "d:/external_pm/";
use Data::Dumper;
print Dumper @INC;
}
Which works as expected and shows:
$VAR1 = 'D:/perl/5163/site/lib';
$VAR2 = 'D:/perl/5163/lib';
$VAR3 = '.'; # I am not sure about this one?!
$VAR4 = 'd:/external_pm/';
Now I want to import a module right after the push:
use strict;
use warnings;
BEGIN {
push @INC, "d:/external_pm/";
use Data::Dumper;
print Dumper @INC;
use ExtScript;
}
The error which follows is showing me that @INC was not updated:
Can't locate ExtScript.pm in @INC (@INC contains: D:/perl/5163/site/lib
D:/perl/5163/lib .) at file.pl line 9.
BEGIN failed--compilation aborted at file.pl line 9.
Why the @INC it's not updating?
I can't import a module in the BEGIN block? Or is a missusage of Perl?