Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Module usage

by ezekiel (Pilgrim)
on Jul 22, 2002 at 01:15 UTC ( #183907=perlquestion: print w/replies, xml ) Need Help??
ezekiel has asked for the wisdom of the Perl Monks concerning the following question:

I have a CGI script using a number of modules (objects) to handle the guts of the processing work. While trying to debug this script I added a warn message to the module I thought the script was using. This warn message never appeared in the logs.

For better or for worse (probably worse), there are multiple copies of this particular module strewn around the file system. Is there any easy way to check the file location of the module whenever a new instance of the object or a method call is made to make sure I am editing the right piece of code in trying to fix bugs


Replies are listed 'Best First'.
Re: Module usage
by Chmrr (Vicar) on Jul 22, 2002 at 01:30 UTC

    After you load the module(s), print out the %INC global. This will tell you the locations of the files which have been included via use or require; for example, try perl -e 'require CGI; use Data::Dumper; print Dumper(\%INC)'

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Re: Module usage
by clintp (Curate) on Jul 22, 2002 at 01:30 UTC
    The hash %INC might have your answer:
    use CGI::Carp; print $INC{'CGI/'};
    Would pull in that module, and then tell you where it found the code at.
Re: Module usage
by dpuu (Chaplain) on Jul 22, 2002 at 01:31 UTC
    You can use %INC. Its like @INC, only the hash key is the name of the file you want to find. For example:
    use Data::Dumper; print $INC{"Data/"};
    A slight bug in this (IMHO) is that you can't use a module name (i.e. $INC{"Data::Dumper"} won't work). You have to use the filename of the module. Oh, and you have to "use" or "require" the module before %INC includes the module's file. --Dave.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://183907]
Approved by erikharrison
[marioroy]: In Saudi Arabia caught fire but didn't burn. I think angels exist.
Lady_Aleena clean up after dinner finally.
[Discipulus]: uch! so we are twice lucky to have MCE..;=)
[marioroy]: Working a midnight graveyard shift, on the way home ran out of gas. just 2 minutes later somebody stops with a small tank of gas. It's wierd. There's always someone nearby for some reason.
[Lady_Aleena]: I was the one who stop[ed in the middle of a cold night to pick up a small family walking to a gas station. I got a few gallons of free gas for the round trip, and the grandmother said she'd pray for me.
[marioroy]: Folks do not know it, but MCE was ridiculously difficult. At Niagra Falls, heard a voice on enabling Grace while in the mist boat. That 10x performance is possible.
[marioroy]: Lady_Aleena Angels on earth are real people. That's awesome.
[Lady_Aleena]: marioroy, what does MCE stand for in this instance? There are 3 pages of abbreviations to go through.
[Lady_Aleena]: ^ or Discipulus...
[marioroy]: Many-core Engine

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2017-05-29 08:26 GMT
Find Nodes?
    Voting Booth?