in reply to Re: Use of %INC ?
in thread Use of %INC ?

When should I use this variable? this is what my questions.

Replies are listed 'Best First'.
Re^3: Use of %INC ?
by psini (Deacon) on Jul 18, 2009 at 10:54 UTC

    As javafan said, "probably never, and if you do, just for read access".

    Perl use this variable to remember which modules have already been loaded, and kindly allows you to see it. This doesn't meen that you are compelled to fiddle with it. The only use I can think of at present, is to see if a module has been loaded, perhaps by other modules.

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Re^3: Use of %INC ?
by parv (Parson) on Jul 18, 2009 at 10:58 UTC

    Post JavaFan correction: Ignore this please for it is disinformation. Or, run s[\%INC][\@INC]g before reading.

    Use it when you are trying to see just what kind of gunk^Wdirectory paths %INC is filled up with, when you know you have installed a module but perl is failing to find one.

    Other similar use is when trying to sort out the module paths, say to clean up the duplicates.

    Well, that is when I personally (have) use(d) %INC anyway.

      Use it when you are trying to see just what kind of gunk^Wdirectory paths %INC is filled up with, when you know you have installed a module but perl is failing to find one.
      Actually, in such a case @INC is far more useful than %INC. %INC just gives you information where Perl actually has found a module it loaded - it doesn't give you much useful information if it couldn't find a module.
      Other similar use is when trying to sort out the module paths, say to clean up the duplicates.
      Again, in that case, @INC is far more useful than %INC.
        Ah, indeed! I misremembered that. Thank you for putting a stop on spread of disinformation.
Re^3: Use of %INC ?
by jhourcle (Prior) on Jul 19, 2009 at 01:29 UTC

    I've typically used it for either finding out what modules are loaded, or for trying to track down where they're loaded from (when you're cleaning up an old machine, and can't figure out why you're not getting the version of the module you're expecting.)

    I keep the following one-liner shell script around as 'whichpm' :

    echo 'print map { sprintf( "%20s : %s\n", $_, $INC{$_} ) } sort keys %INC; print "\n'$1' version : $'$1'::VERSION\n\n"' | perl "-M$1"