Is there an equivalent to the perl debugger 'x' in pdl2 (or Devel::REPL)?
Asked Answered
A

2

10

I am using pdl2 (the PDL shell) also as a my default Perl interactive shell (it loads all the nice plugins for Devel::REPL). But I am missing the x dumper-printing alias. p is nice for piddles but it does not work for a normal array ref or hash ref. I have loaded Data::Dumper but it lacks an easy way of controlling depth and I like the way you can quickly set depth limits with x, e.g. x 2 $deep_datastruct for complex data structures. But with Data::Dumper the process is more cumbersome:

pdl> say $c
HASH(0x53b0b60)

pdl> p $c
HASH(0x12b14018)

pdl> use Data::Dumper

pdl> p Dumper $c
$VAR1 = {
          'c' => {
                   'c' => 3,
                   'a' => 1,
                   'b' => {
                            'c' => '3',
                            'a' => '1',
                            'b' => '2'
                          }
                 },
          'a' => 1,
          'b' => 4
        };
pdl>  $Data::Dumper::Maxdepth = 1;
pdl> p Dumper $c
$VAR1 = {
          'c' => 'HASH(0x97fba70)',
          'a' => 1,
          'b' => 4
        };

In the Perl debugger you can achieve the same thing with x 1 $c directly. Does pdl2 have something similar and so concise?

[update] And related with this question: does pdl2 or Devel::REPL have convenience functions like the Perl debugger commands m or y? Or should one create a module with PadWalker and export them? I would like to use a real REPL instead of the Perl debugger as an interactive shell, but still the Perl debugger has some important things that I don't know how to do with Devel::REPL or pdl2.

For example to see all variables (pdl2 only show piddles):

pdl> help vars
PDL variables in package main::

Name         Type   Dimension       Flow  State          Mem
----------------------------------------------------------------
no PDL objects in package main::

By the way, does someone know a Devel::REPL plugin for listing all the variables in use (like y in the debugger, but only the names, not the values) and then have a x-like to dump the wanted one?

Agadir answered 10/10, 2010 at 1:4 Comment(0)
L
4

It looks like Devel::REPL provides an straightforward alternative for your first question. Create a file called '.perldlrc' in your home directory that looks like:

use Data::Dumper;

sub x { 
  my $depth = shift;
  $Data::Dumper::Maxdepth = $depth;
  print Data::Dumper->Dump([@_])
}

Unfortunately, you need a comma as in:

pdl> x 1, $c

It looks like you can implement the other commands with this same control-file approach. I don't see a way to get rid the need for the comma, although I don't think there's any reason Devel::REPL cannot be made to recognize and parse these kinds of commands.

Lindsey answered 16/2, 2011 at 5:57 Comment(0)
F
0

The Devel::REPL shell re.pl already dumps the value of the last expression by default:

[foo@host]$ re.pl
$ { a => 23, b => 34}
$HASH1 = {
           a => 23,
           b => 34
         };

$ 
Fayfayal answered 14/12, 2010 at 15:23 Comment(1)
That is the problem, I have this option off because if you have a mastodontic composite object with one of the subojects being the return of a database with 10000 rows, you don't want to print out everyting. Probably you would like to print only the first level of the hash to see which subojects contain (like db> x 2 $mastobject).Agadir

© 2022 - 2024 — McMap. All rights reserved.