Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Neat Debugger tricks

by johnnywang (Priest)
on Nov 16, 2005 at 20:09 UTC ( #509175=note: print w/replies, xml ) Need Help??

in reply to Neat Debugger tricks

I've also been using the debugger quite often recently because of inherited code. The ones I use most:
  1. break at a line number: b 234
  2. break at a function : b foo
  3. simply change the value of a variable, e.g, the script is processing all files a directory, so it got a list at the beginning, I only want to look at a particular file, I can simply break after gettting the list, then change the list to contain that particular file.
  4. dump a data structure: use Data::Dumper; p Dumper($foo)

Replies are listed 'Best First'.
Re^2: Neat Debugger tricks
by QM (Parson) on Nov 17, 2005 at 03:49 UTC
    4. dump a data structure: use Data::Dumper; p Dumper($foo)
    Unless you're just sweet on D::D, I prefer
    x $foo
    For hashes, this works better:
    x \%foo

    Quantum Mechanics: The dreams stuff is made of

      If the output from x (or p) is too long for your screen then prepend the pipe. The output will be piped through less (or whatever 'o pager' is set to) and you can scroll back and forth at your pleasure.
      harleypig@harleypig ~ $ perl -de 0 Loading DB routines from version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 0 DB<1> o pager? pager = '|/usr/bin/less' DB<2> |x \%::
      and the output is the same as 'x \%::' but in a less session.
      Harley J Pig
Re^2: Neat Debugger tricks
by tye (Sage) on Nov 17, 2005 at 06:05 UTC

    Why use Data::Dumper? Do you know about the "x" command? Of course, for me, it isn't just the 1 character versus a few dozen; it is that the default format that Data::Dumper produces is just horribly awful and the format the "x" command uses is quite nice.

    I was about to hack into the debugger the ability to control how deep complex structures are dumped. Unfortunately, "hashDepth" already existed and has nothing to do with "depth", but instead controls the length of dump produced. Not everyone "gets" English. (: Luckily I see that someone solved this problem with "dumpDepth".</ramble>

    - tye        

      I'm betting he uses Data::Dumper instead of 'x' for the same reason I do: inertia. I've become so used to Dumper output that I can just glance at it and see what's going on. The output from 'x' is always a mental speedbump for me. I'm not saying it's bad, it's just not what I'm used to and I don't use the debugger often enough for this to be an issue.


      New address of my CGI Course.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://509175]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2020-09-25 08:03 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (136 votes). Check out past polls.