Adrian Adrian - 3 months ago 8
Perl Question

How to run `x` command within a < action in the perl debugger?

I'd like to get a semicomplex structure to be output before displaying the prompt in the debugger. The best way to display it is to use the

x
command, but the command isn't available under that name or perhaps it's not in scope.

How would I accomplish this?

Answer

See the documentation for < [command] in perldebug:

< [ command ]

Set an action (Perl command) to happen before every debugger prompt.

x is not a Perl command. You want { [command]:

{ [ command ]

Set an action (debugger command) to happen before every debugger prompt.

For example:

$ perl -de'$foo = { foo => "bar" };
           print $foo'

Loading DB routines from perl5db.pl version 1.37
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(-e:1):   $foo = { foo => "bar" };
  DB<1> { x $foo
  DB<2> n
main::(-e:2):   print $foo
auto(-1)  DB<2> x $foo
0  HASH(0x22af2c8)
   'foo' => 'bar'

Alternatively, use your favorite dumper module (e.g. Data::Dumper, Data::Dump, Data::Printer):

$ perl -de'$foo = { foo => "bar" };
           print $foo'

Loading DB routines from perl5db.pl version 1.37
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(-e:1):   $foo = { foo => "bar" };
  DB<1> use Data::Dumper

  DB<2> < print Dumper $foo
  DB<3> n
main::(-e:2):   print $foo
$VAR1 = {
          'foo' => 'bar'
        };