saintmike has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way in perl's debugger to watch a reference or a memory location? Let's say, with code like
1: my %hash = (a => 'b'); # Watch %hash 2: 3: my $ref = \%hash; # Breakpoint! 4: ### ... some code ... 5: my $otherref = \%hash; # Breakpoint! 6: my $yetanotherref = $otherref; # Breakpoint!
is there a way in line 1 (or 3) to set a watch point in the debugger so that whenever %hash is referenced somehow (for reading or writing), the debugger stops?

Or is there a way to say "whenever you reference HASH(0x81049b0), let the debugger stop"?

Any help apprechiated.

Replies are listed 'Best First'.
Re: How to watch a reference in the debugger?
by Old_Gray_Bear (Bishop) on Jun 06, 2004 at 18:50 UTC
    Take a look at the debugger 'w' command -- set global watch point. (Sorry, I don't know which release of Perl brought it in; it's in the 5.8.x versions and I don't remenber it using it with 5.6.x.)

    I don't know how it will work against a reference, you may have to watch the base variable. ('w %hash'rather than 'w \%hash').

    ----
    I Go Back to Sleep, Now.

    OGB

Re: How to watch a reference in the debugger?
by ambrus (Abbot) on Jun 06, 2004 at 19:14 UTC

    IIRC someone has mentioned a module that does this kind of debugging with tied variables. Try to super-search for it.

    Update: here's it: Debugging with tied variables