Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Can someone explain to me why, sometimes, %INC contains empty values? For example:

( "A.pm" => "/usr/share/perl/5.xx/A.pm", "B.pm" => undef, ... )

The problem is, I can't pinpoint or reproduce this right now. I've encountered this more than a couple of times, first on a laptop, then on a server, causing this code if ($INC{$mod}) { eval { require $mod } } to fail.

Does undef value on an entry in %INC have any useful meaning? Or is it a bug with some code, somewhere that sets %INC? I'm pretty sure none of my code modifies %INC in anyway. Have someone experienced this too?

Replies are listed 'Best First'.
Re: Undefined entries in %INC?
by ig (Vicar) on Aug 28, 2012 at 06:08 UTC
    Does undef value on an entry in %INC have any useful meaning?

    See require. An undef value for an entry in %INC may record the fact that an attempt to include a file failed, at least in some cases. But if it was set by means other than require, it may indicate something else. The only aspect of the value that is well defined is that it should be true if the file was included successfully and false otherwise. undef is just one of the false values.

Re: Undefined entries in %INC?
by Anonymous Monk on Aug 28, 2012 at 02:24 UTC

    Does undef value on an entry in %INC have any useful meaning?

    Nope. It only means someone carelessly put stuff into %INC