Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Almost 3 years later, I actually tried this. It does not appear to work: execution does not stop when the variable changes value, and the L command does not show the watchpoint. My Perl version is 5.8.8; that might be important.

You're right, the solution is pretty simple. Create a ref to the variable of interest and make the watchpoint the dereferenced value. This has the very slight disadvantage of having to wait until the variable of interest has been created, but avoiding the maddening interruptions is wonderful!

Program slightly modified for demonstration purposes:

use strict; my $t = 14; print "$t\n"; $t = 15; print "$t\n"; blah(); print "$t\n"; sub blah { my $t = 42; print "$t\n"; }

Debug session - Was:

DB<1> w $t DB<2> c Watchpoint 0: $t changed: old value: '' new value: '14' main::(dbt.pl:4): print "$t\n"; DB<2> c 14 Watchpoint 0: $t changed: old value: '14' new value: '15' main::(dbt.pl:6): print "$t\n"; DB<2> c 15 Watchpoint 0: $t changed: <<<<< the bane of my existence old value: '15' new value: '42' main::blah(dbt.pl:12): print "$t\n"; DB<2> c 42 Watchpoint 0: $t changed: <<<<< just more bane old value: '42' new value: '15' main::(dbt.pl:8): print "$t\n"; DB<2> c 15 Watchpoint 0: $t changed: old value: '15' new value: '' Debugged program terminated.

Now:

DB<1> w $t DB<2> c Watchpoint 0: $t changed: old value: '' new value: '14' main::(dbt.pl:4): print "$t\n"; DB<2> W $t DB<3> $z=\$t DB<4> w $$z DB<5> c 14 Watchpoint 0: $$z changed: old value: '14' new value: '15' main::(dbt.pl:6): print "$t\n"; DB<5> c 15 42 15 Watchpoint 0: $$z changed: old value: '15' new value: '' Debugged program terminated.
But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)


In reply to Re^2: Debugger Questions - Variable Scope (source++) by GotToBTru
in thread Debugger Questions - Variable Scope by GotToBTru

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-19 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found