有两种情况我的代码不会导致分段错误:
- 当我在至少一处使用Smart::Comments时
- 运行调试器。
我已经追踪到这个电话:
$action->{breakdown}
= join( ' '
, each_pair {
my ( $name, $length ) = @_;
return "x$length" if $name eq 'FILLER';
push @$field_list_ref, $name;
return "A$length";
} @$field_def_ref
);
其中each_pair
在另一个模块中定义为:
sub each_pair (&@) {
my $block = shift;
return unless @_;
my $caller = caller();
my $aref = qualify( 'a', $caller );
my $bref = qualify( 'b', $caller );
my @results;
my $pairs = 0;
for ( my $index = 0; $index < $#_; $index += 2 ) {
$pairs++;
my @pair = @_[$index..($index+1)];
no strict 'refs';
local ( $$aref, $$bref ) = @pair;
push @results, $block->( @pair );
}
return wantarray || $pairs != 1 ? @results : shift @results;
}
- 现在我知道我可以用List::MoreUtils::natatime 替换 each_pair(虽然我听说这有一些错误),他们最近才允许这个模块进入我们的环境,我仍然对这个调用为什么会导致感兴趣分段错误——或者其他 Perl 程序员由于调试分段错误而导致的错误。
我在这方面浪费了一些时间。
编辑
我有其他模块使用此功能,有些人希望能够使用$a
and $b
,它也在同一模块的其他地方工作,用于另一个列表。我可以更改对它的调用,我可以为这个文件更改它,但是为每个成功使用它的地方更改它,可能比我在这么晚的时间允许做的更改更多。