in reply to How can I prevent a module from being added to the %INC hash?

I think you're on the right track with the BEGIN block. Here's an example that (I hope) removes Net::FTP and any modules loaded by Net::FTP from %INC:
BEGIN { use strict; use warnings; use Carp; use Digest::MD5; our %inc_copy = %INC; }; use Net::FTP; %INC = %inc_copy; for(keys(%INC)) {print "$_: $INC{$_}\n"}

Note that I explicitly loaded Carp.pm, and that Net::FTP also loads Carp.pm. Do you therefore require that Carp.pm not appear in %INC ?
With the above example, Carp.pm still appears in %INC.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: How can I prevent a module from being added to the %INC hash?
by jacques (Priest) on Oct 04, 2006 at 03:29 UTC
    One problem: What if you are putting the code above into a module and then use that module in a program? The %INC hash will contain all the modules that the program uses as well. And those modules will not be in the %INC hash when you assign it to %inc_copy.
      What if you are putting the code above into a module and then use that module in a program?

      I might be missing something here, but it still seems to work ok:
      ## My_Foo.pm package My_Foo; BEGIN { use strict; use warnings; use Carp; use Digest::MD5; our %inc_copy = %INC; }; use Net::FTP; %INC = %inc_copy; 1;
      ## test.pl use Math::BigInt; use My_Foo; for(keys(%INC)) {print "$_: $INC{$_}\n"}

      Net::FTP and the modules it loads are still missing from %INC.

      Cheers,
      Rob
        When I run this, Net::FTP is there. Thanks though. You made me think about it in a new way.