printing all commands' return value in debugger

Discussion in 'Perl Misc' started by yary, Feb 21, 2007.

  1. yary

    yary Guest

    I'm often using the debugger as a scratchpad to try things out. I'd
    like to see the return value of all commands I type, so I don't have
    to start each line with "p"- that is, something like:

    > perl -de 1

    DB<1> $a=5
    5
    DB<2> $a
    5
    DB<3> print $a
    5
    1

    I can't figure out how to twist the debugger commands/options around
    to get this "auto-print" going! Any ideas?
    yary, Feb 21, 2007
    #1
    1. Advertising

  2. yary

    Guest

    On Feb 21, 11:21 am, "yary" <> wrote:
    >
    > I'm often using the debugger as a scratchpad to try things out. I'd
    > like to see the return value of all commands I type, so I don't have
    > to start each line with "p"- that is, something like:
    >
    > > perl -de 1

    >
    > DB<1> $a=5
    > 5
    > DB<2> $a
    > 5
    > DB<3> print $a
    > 5
    > 1
    >
    > I can't figure out how to twist the debugger commands/options around
    > to get this "auto-print" going! Any ideas?



    I remember seeing someone's post a few years ago that addressed a
    similar issue, but for the life of me I can't seem to locate it.

    Anyway, you could try the follwoing:

    perl -wne 'print eval, "$@\n> "' # for UNIX
    perl -wne "print eval, qq/$@\n> /" # for DOS

    That way, you can type the following input and get the following
    output:

    > $a=5

    5
    > $a

    5
    > print $a

    51

    (Note that "51" shows up because you didn't print a newline after
    printing $a.)

    (Also note that, unlike the debugger, you can't exit by typing "q".
    Instead, you exit by typing "exit".)

    This is pretty much what you wanted, right? To be honest, I don't
    really see what's so hard about using the regular perl debugger and
    typing "p" or "x" before every statement (I would think that's easier
    than typing out the full one-liner I gave above), but if you prefer it
    that way, go ahead and use it.

    (Like you, I use the debugger as a scratchpad all the time, but I
    don't consider typing "x" in front of statements to be a hassle.)

    I hope this helps, yary.

    -- Jean-Luc
    , Feb 21, 2007
    #2
    1. Advertising

  3. yary

    yary Guest

    Thanks! That will work... it's not so much a hassle, it's more that I
    forget, and if there are side-effects I may need to start all over
    again when I do forget a critical p/x.
    yary, Feb 21, 2007
    #3
  4. yary

    Peter Scott Guest

    On Wed, 21 Feb 2007 10:21:19 -0800, yary wrote:
    > I'm often using the debugger as a scratchpad to try things out. I'd
    > like to see the return value of all commands I type, so I don't have
    > to start each line with "p"- that is, something like:
    >
    >> perl -de 1

    > DB<1> $a=5
    > 5
    > DB<2> $a
    > 5
    > DB<3> print $a
    > 5
    > 1
    >
    > I can't figure out how to twist the debugger commands/options around
    > to get this "auto-print" going! Any ideas?


    You could copy perl5db.pl and modify it to do what you want where it
    decides to eval the input as Perl code. Then invoke it via

    perl -d:myperl5db ...

    Personally I wouldn't, since I often do things in the debugger to modify
    variables in the program like

    DB<1> @some_array = <very long list>

    which would clog up your screen.

    --
    Peter Scott
    http://www.perlmedic.com/
    http://www.perldebugged.com/
    Peter Scott, Feb 22, 2007
    #4
    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. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    3,952
    Thomas Stegen
    Jun 28, 2003
  2. Tim Stanka
    Replies:
    1
    Views:
    785
    Jeff Epler
    Aug 2, 2004
  3. Greenhorn
    Replies:
    15
    Views:
    801
    Keith Thompson
    Mar 6, 2005
  4. Larry
    Replies:
    7
    Views:
    468
    Larry
    Aug 15, 2007
  5. Robert Oschler
    Replies:
    1
    Views:
    215
    Mcginkel
    Sep 5, 2005
Loading...

Share This Page