printing all commands' return value in debugger

Y

yary

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?
 
J

jl_post

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:


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
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
 
Y

yary

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.
 
P

Peter Scott

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:

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top