Variable introspection when using require()

D

Derek Basch

Hello,

I have a huge mess of a program that uses a bunch or require()
statements. Also many of the required scripts have require()'s as well.
How do I find where the value of a variable named $address is being set
in the require tree?

Thanks,
Derek
 
J

jdrago_999

Your question is extremely vague.

Please restate your question(s) as clearly as possible.
 
D

Derek Basch

I don't know how to make it any clearer.

I inherited a huge script that has alot of require()'s. During the
execution of the script the value of a variable named $address is set.
The value is not set within the script but within one of the scripts
imported using require(). How do I find which require()'d script the
value of the variable is being set within?

Thanks,
Derek
 
J

J. Gleixner

Derek said:
I don't know how to make it any clearer.

I inherited a huge script that has alot of require()'s. During the
execution of the script the value of a variable named $address is set.
The value is not set within the script but within one of the scripts
imported using require(). How do I find which require()'d script the
value of the variable is being set within?

Look through the required files for where it's set.

find . -exec grep -l '$address' {} \;
 
T

Tad McClellan

Derek Basch said:
I inherited a huge script that has alot of require()'s. During the
execution of the script the value of a variable named $address is set.
The value is not set within the script but within one of the scripts
imported using require(). How do I find which require()'d script the
value of the variable is being set within?


foreach my $fname ( values %INC ) {
open my $progfile, $fname or die "could not open '$fname' $!";
while ( <$progfile> ) {
next unless /\$address/;
print "$fname: $_";
}
close $progfile;
}
 
B

Brian McCauley

Derek said:
I have a huge mess of a program that uses a bunch or require()
statements. Also many of the required scripts have require()'s as well.
How do I find where the value of a variable named $address is being set
in the require tree?

The general solution to finding where a variable is getting changed is
to do something like..

use Carp;
use AtExit;
BEGIN { our $address = AtExit->new(sub{
local $Carp::CarpLevel=4;
Carp::cluck '$address has been changed';
}) }

Note: I detemined the value 4 heuristically. It may be wrong if you
have a different AtExit::VERSION

This, of course, assumes that setting the value of $address before you
reach the point at which it would normally be set doesn't alter the
behaviour of your scripts.
 
J

jdrago_999

Another way trick that might help is to dump the contents of %INC to
see what it contains:

use Data::Dumper;
print Dumper( \%INC );

It might help, though it might not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top