首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用我的.perldlrc中的一些代码在pdl2中出现分段错误,这些代码可以直接从pdl2外壳中正常工作

使用我的.perldlrc中的一些代码在pdl2中出现分段错误,这些代码可以直接从pdl2外壳中正常工作
EN

Stack Overflow用户
提问于 2011-07-09 04:58:17
回答 1查看 124关注 0票数 1

组合

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,如下所示

代码语言:javascript
复制
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,但这些方法都不起作用:

代码语言:javascript
复制
$ pdl2
pdl> $xx=in_scope_variables()
Runtime error: You can't FIRSTKEY with the %~ hash at (eval 254) line 38

pdl> lvars
Segmentation fault

如果我注释了这个循环

代码语言:javascript
复制
# for my $name (keys %main::) {
#     [...]
# }

那么只有lvars失败:

代码语言:javascript
复制
pdl> $xx=in_scope_variables()
pdl> lvars                   
Segmentation fault

但是,如果我直接在pdl2外壳中运行代码,它就可以工作

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-09 05:33:26

  • 解决了分段故障:

我已经更新了我一年前的PadWalker版本,现在有了PadWalker-1.92,它就可以工作了。

不幸的是,我在更新之前没有写下我的版本,所以我不能报告我在哪个版本上遇到了问题。

捕获%main::变量时,

  • 仍挂起错误:

运行时错误:不能在第38行使用%~哈希值进行FIRSTKEY

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6630447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档