Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^5: [perldebugger] calling perldoc from within the debugger (inifile)

by pemungkah (Priest)
on Sep 02, 2009 at 00:01 UTC ( #792770=note: print w/replies, xml ) Need Help??

in reply to Re^4: [perldebugger] calling perldoc from within the debugger (inifile)
in thread [perldebugger] calling perldoc from within the debugger

Hm. Might be able to do it by altering sub eval() ... yes, quite easily!

Setting $DB::onetimeDump to 'dump' and calling DB::eval will do exactly what you want. Try this in your .perldb:

sub DB::new_eval { local $DB::onetimeDump = 'dump'; &DB::old_eval(@_); + } *DB::old_eval = \&DB::eval; *DB::eval = \&DB::new_eval;
It's perldb.ini if you're on Windows. You get output like this:
[tearought-lm|(none)]04:54 PM $ perl -de0 Loading DB routines from version 1.31 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 0 DB<1> [1..10] 0 ARRAY(0x800cc0) 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 DB<2>
This is just copying the old eval to a new name, creating a new sub that calls it after setting up $onetimeDump property, and substituting the new sub for the old one. it's not perfect:
DB<4> print "my father plays dominos\n" my father plays dominos 0 1 DB<5>
but should basically do what you're looking for. You'd need to patch up the dumping function a little more for perfection.

Replies are listed 'Best First'.
Re^6: [perldebugger] calling perldoc from within the debugger (REPL) (THX!)
by LanX (Sage) on Sep 02, 2009 at 23:02 UTC
    Thanx, look really easy ... nice work pemungkah! 8)

    I have to figure out a good automated context strategy...

    ... hmm ...I think it's appropriate to default to list evaluation like with the x-cmd since I can always use scalar to do otherwise.

    But it's somehow useless to get just one line with index 0 for dumping a scalar

    DB<4> print "my father plays dominos\n" my father plays dominos 0 1

    Do you know a way to change this behavior automatically for a one element list like with p-cmd?

    DB<4> print "my father plays dominos\n" 1my father plays dominos

    as far as I can understand from the docs of DB it's neccessary to manipulate to achieve this... right?

    Cheers Rolf

      What you're seeing here is an 'x' of the print's return value, which is of course 1 since the print succeeded. We can expand the replacement eval with a crude check for the function being a print, in which case we leave $onetimeDump off.
      sub smarter_eval { local $onetimeDump = 'dump' if $_[0] =~ /\Aprint\s*\(?/; old_eval(@_); }
Re^6: [perldebugger] calling perldoc from within the debugger (REPL)
by LanX (Sage) on Feb 02, 2012 at 00:17 UTC
    Thanks again, I'm using this now regularly! :)

    DB<26> 1..9,[a..b] => (1, 2, 3, 4, 5, 6, 7, 8, 9, ["a", "b"])

    to be precise I tweaked the debugger to use Data::Dump::qq() for printing.

    Cheers Rolf

      I think this is useful enough I should make it into a patch. I'll do that. It'll need a way to toggle it on and off, etc. but that's all a SMOP.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2022-05-23 12:05 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (82 votes). Check out past polls.