Re: printing all commands' return value in debugger



On Feb 21, 11:21 am, "yary" <not....@xxxxxxxxx> 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

.



Relevant Pages