It doesn't work due to how BEGIN blocks and use statements are compiled/executed. If you take the use out of the equation, you can see that there's nothing special about %INC:
For example, compare the difference between these two commands:
perl -e'BEGIN{ eval "use Net::FTP;" } print %INC'
and
perl -e'BEGIN{ local %INC = %INC; eval "use Net::FTP;" } print %INC'
The only difference between the two is the localization of %INC in the BEGIN block.
Of course, doing an eval on the string is slow. The OP might want to use a require inside a BEGIN block, instead:
BEGIN { # Hide the fact that our module was imported.
local %INC = %INC;
require Net::FTP;
# call import() if necessary
}
|