组合
Is there an equivalent to the perl debugger 'x' in pdl2 (or Devel::REPL)?
和
How can I list all variables that are in a given scope?
我创建了perldlrc,如下所示
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;
}然后我启动了pdl2,但这些方法都不起作用:
$ pdl2
pdl> $xx=in_scope_variables()
Runtime error: You can't FIRSTKEY with the %~ hash at (eval 254) line 38
pdl> lvars
Segmentation fault如果我注释了这个循环
# for my $name (keys %main::) {
# [...]
# }那么只有lvars失败:
pdl> $xx=in_scope_variables()
pdl> lvars
Segmentation fault但是,如果我直接在pdl2外壳中运行代码,它就可以工作
pdl> $xx=in_scope_variables()
pdl> x 1, $xx
$VAR1 = {
'$_REPL' => 'REF(0x19999708)'
};
pdl> print Dumper [keys %$xx];
$VAR1 = [
'$_REPL'
];有人知道为什么会发生这两个错误吗?
这是一个pdl2问题,Devel::REPL问题,还是我在做一些愚蠢的事情?
我使用的是Perl5.12和Perldl2 Shell v0.005
发布于 2011-07-09 05:33:26
我已经更新了我一年前的PadWalker版本,现在有了PadWalker-1.92,它就可以工作了。
不幸的是,我在更新之前没有写下我的版本,所以我不能报告我在哪个版本上遇到了问题。
捕获%main::变量时,
运行时错误:不能在第38行使用%~哈希值进行FIRSTKEY
https://stackoverflow.com/questions/6630447
复制相似问题