combining
Is there an equivalent to the perl debugger 'x' in pdl2 (or Devel::REPL)?
and
How can I list all variables that are in a given scope?
I have created my perldlrc like
use feature ':5.10';
use Data::Dumper;
use PadWalker qw/peek_our peek_my/;
sub x {
my $depth = shift||0;
$Data::Dumper::Maxdepth = $depth;
print Data::Dumper->Dump([@_])
}
sub lvars {
my $vars = in_scope_variables();
print Dumper [keys %$vars];
}
sub in_scope_variables {
my %in_scope = %{peek_our(1)};
my $lexical = peek_my(1);
for my $name (keys %main::) {
my $glob = $main::{$name};
if (defined ${$glob}) {
$in_scope{'$' . $name} = ${$glob};
}
if ( @{$glob}) {
$in_scope{'@' . $name} = [@{$glob}];
}
if (%{$glob}) {
$in_scope{'%' . $name} = {%{$glob}};
}
}
#lexicals hide package variables
while (my ($var, $ref) = each %$lexical) {
$in_scope{$var} = $ref;
}
return \%in_scope;
}
Then I start pdl2 but the methods do not work:
$ pdl2
pdl> $xx=in_scope_variables()
Runtime error: You can't FIRSTKEY with the %~ hash at (eval 254) line 38
pdl> lvars
Segmentation fault
If I commented the loop
# for my $name (keys %main::) {
# [...]
# }
Then only lvars fail:
pdl> $xx=in_scope_variables()
pdl> lvars
Segmentation fault
But if I run the code directly in the pdl2 shell it works
pdl> $xx=in_scope_variables()
pdl> x 1, $xx
$VAR1 = {
'$_REPL' => 'REF(0x19999708)'
};
pdl> print Dumper [keys %$xx];
$VAR1 = [
'$_REPL'
];
Do someone have any idea why this two errors happens?
Is that a pdl2 problem a Devel::REPL problem or me doing something stupid?
I am using perl 5.12 and Perldl2 Shell v0.005