Variable introspection when using require()

Discussion in 'Perl Misc' started by Derek Basch, Apr 24, 2006.

  1. Derek Basch

    Derek Basch Guest

    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
     
    Derek Basch, Apr 24, 2006
    #1
    1. Advertising

  2. Derek Basch

    jdrago_999 Guest

    Your question is extremely vague.

    Please restate your question(s) as clearly as possible.
     
    jdrago_999, Apr 24, 2006
    #2
    1. Advertising

  3. Derek Basch

    Derek Basch Guest

    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
     
    Derek Basch, Apr 24, 2006
    #3
  4. Derek Basch

    J. Gleixner Guest

    Derek Basch wrote:
    > 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' {} \;
     
    J. Gleixner, Apr 25, 2006
    #4
  5. Derek Basch <> wrote:

    > 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;
    }


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 25, 2006
    #5
  6. Derek Basch wrote:

    > 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.
     
    Brian McCauley, Apr 25, 2006
    #6
  7. Derek Basch

    jdrago_999 Guest

    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.
     
    jdrago_999, Apr 25, 2006
    #7
  8. Derek Basch

    Derek Basch Guest

    Thanks for the help everyone!

    Derek Basch
     
    Derek Basch, Apr 26, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Smith
    Replies:
    0
    Views:
    323
    David Smith
    Jul 11, 2003
  2. John Harrison

    Re: class introspection

    John Harrison, Jul 23, 2003, in forum: C++
    Replies:
    4
    Views:
    377
    John Harrison
    Jul 24, 2003
  3. Benjamin Rutt
    Replies:
    4
    Views:
    396
    Mike Meyer
    Jul 8, 2005
  4. Replies:
    6
    Views:
    285
    Bruno Desthuilliers
    Aug 27, 2006
  5. EricGoogle
    Replies:
    12
    Views:
    179
    Thomas 'PointedEars' Lahn
    May 19, 2008
Loading...

Share This Page