in reply to Use of %INC ?

I don't know what your question is. Do you mean "how can I use this variable?" In that case, the answer is, "in the same way you use any other hash". Or perhaps you mean "when should I use this variable?" In which case the answer is "probably never, and if you do, just for read access".

Replies are listed 'Best First'.
Re^2: Use of %INC ?
by vinoth.ree (Monsignor) on Jul 18, 2009 at 10:45 UTC

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

      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."

      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.

      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"