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