You can stack the necessary commands in the .perldb file to automate the turning on/turning off of Devel::Carnivore. Here's the program stripped down:
use strict; use warnings; my $h; { my %h; # watch from here ... $h{fname} = "Foo"; $holder = \%h; } $holder->{lname} = 'Bar'; $holder->{email} = 'foo@bar.com'; # ... to before here
And here's .perldb to watch %h as noted:
push @DB::typeahead, (split /\n/, <<EOS); # Load Carnivore use Devel::Carnivore # Line to start watching on c 7 watch(\\%h) # run to point where we want to switch off c 13 # do so unwatch \$h # run to end of program c # quit debugger q EOS
Run this as perl -d <your program>. The output:
01:26 PM $ perl5.8.5 -d z.pl Loading DB routines from perl5db.pl version 1.27 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(z.pl:4): my $h; main::(z.pl:5): { auto(-12) DB<1> use Devel::Carnivore auto(-11) DB<2> # Line to start watching on auto(-10) DB<3> c 7 main::(z.pl:7): $h{fname} = "Foo"; auto(-9) DB<4> watch(\%h) # variable is now under observation auto(-8) DB<5> # run to point where we want to switch off auto(-7) DB<6> c 13 > "fname" changed from "" to "Foo" at z.pl line 7 > "lname" changed from "" to "Bar" at z.pl line 11 main::(z.pl:13): $h->{email} = 'foo@bar.com'; # ... to before her +e auto(-6) DB<7> # do so auto(-5) DB<8> unwatch $h # mission completed auto(-4) DB<9> # run to end of program auto(-3) DB<10> c Debugged program terminated. Use q to quit or R to restart, use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. auto(-2) DB<10> # quit debugger auto(-1) DB<11> q 01:26 PM $
The problem, of course, is that you're dependent on line numbers, but there's an example of how to automate the debugger. Removing the comments will of course give you nicer output as well.

In reply to Automating the debugger with Devel::Carnivore by pemungkah
in thread debugging: tracing changes to hashes by szabgab

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.