Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Using Data::Printer from the Perl debugger

by ibm1620 (Hermit)
on Mar 02, 2023 at 02:42 UTC ( [id://11150686]=note: print w/replies, xml ) Need Help??


in reply to Re: Using Data::Printer from the Perl debugger
in thread Using Data::Printer from the Perl debugger

Using pure guesswork, I made one change to DB::Pluggable::Plugin::DataPrinter.pm:
sub initialize { no warnings 'once'; # $DB::alias{p} = 's/^/use Data::Printer; /; eval $cmd'; $DB::alias{p} = 's/^/use Data::Printer; /'; }
Now the p command prints its argument only once.

I inserted print $cmd; before eval $cmd, entered p $my_var in the debugger, and it printed "p $my_var". Apparently the eval was unnecessary.

FWIW.

Replies are listed 'Best First'.
Re^3: Using Data::Printer from the Perl debugger
by LanX (Saint) on Mar 02, 2023 at 08:31 UTC
    You are mangling internal p command and aliases, here are dragons.

    If I were you I'd stick with px

    Otherwise you need to look into the code of perl5db.pl

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

      You are mangling internal p command and aliases

      But isn't that exactly what the author(s) of DB::Pluggable::Plugin::DataPrinter.pm are doing? Or are you saying that approach isn't advisable?

      My only objection to px is I have to explicitly en-reference non-scalars, and I've become used to using the p command without doing that. Not a big deal.... :)

        > of DB::Pluggable::Plugin::DataPrinter.pm are doing?

        I don't know ... I was expecting them to monkey patch the sub for the p cmd. That's why $cmd is set, btw.

        > en-reference non-scalars

        you mean %h -> \%h ... IMHO this could be automatically done with a sub prototype ( like (\[%@$*]) )

        > p command without doing that

        p is for printing x for dumping,

        I'd rather patch x

        DB<1> $x=[1,2,3] DB<2> p $x ARRAY(0x32c8908) DB<3> x $x 0 ARRAY(0x32c8908) 0 1 1 2 2 3 DB<4>

        FWIW you can test aliasing interactively with =

        DB<4> h p p expr Same as "print {DB::OUT} expr" in current package. perldoc manpage Runs the external doc viewer perldoc command on the named Perl manpage, or on perldoc itself if omitted. Set $DB::doccmd to change viewer. DB<5> h x x expr Evals expression in list context, dumps the result. DB<6> h = = [alias value] Define a command alias, or list current aliases. DB<7>

        Cheers Rolf
        (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2025-07-20 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.