Finding what's been added to @INC

Paul Johnson paul at
Tue Jul 15 23:04:32 BST 2008

On Tue, Jul 15, 2008 at 09:03:30PM +0100, Simon Wistow wrote:

> So one solution, suggested by Jess was to exec another Perl and diff 
> their @INCs. We came up with
> my %tmp = map { $_ => 1 } split ':', do
> {
>     local %ENV && delete $ENV{PERL5LIB};
>     `$^X -e 'print join(":", \@INC)'`;
> };
> my @LOCALINC = grep { !$tmp{$_} } @INC;
> print join("\n", @LOCALINC)."\n";

> I keep thinking that there ought to be a better way though.

There ought to be, and having discussed this on p5p I believe the
consensus was that patches would be welcome to store the pristine @INC
in %Config.  I'm afraid that neither I nor anyone else has manged to get
around to doing that though.

Being a bear of very little brain I can offer a worse way though.  In
Devel::Cover I store the @INC at build time and use that as the
baseline.  This is slightly different in that it also stores the changes
that have come in through PERL5LIB or whatever at that time.  But I like
to think of this as a feature.  If they're there when the module is
built they are probably meant to be permanent.

On that note, don't forget about PERLLIB, PERL5OPT and, if you are
feeling suitable paranoid, PERL5DB.  Oh, and  And do
you care about -Duserelocatableinc?  There are probably other ways to do
nasty things too ...

Oh, and you just know that some joker is going to have colons in his
directories.  I think that the only safe character to be using there
might be NUL.  And I don't even want to think about cross-platform

When you are done, would you mind posting your final solution?  I'd like
to nick it ;-)

Paul Johnson - paul at

More information about the mailing list