1;
2;
3;
Run Code Online (Sandbox Code Playgroud)
package DB;
sub DB {
print "HERE";
our(undef, $f, undef) = caller;
# This does not work
# my $ref = \%{ "main::_<$f" };
# $ref->{ 3 } = {};
# This does not work
# *x = $main::{ "_<$f" };
# $x{ 3 } = {};
*dbline = $main::{ "_<$f" };
$dbline{ 3 } = {};
$DB::single = 0;
}
1;
Run Code Online (Sandbox Code Playgroud)
PERL5DB="BEGIN{ require 't.pl' }" perl -d t2.pl
Run Code Online (Sandbox Code Playgroud)
当你运行这个代码时,你得到了HEREHERE,但是当你没有使用别名时,神奇的Perl变量没有效果*dbline.
因此,当您更改前两个示例时,如下所示:
*dbline = $main::{ "_<$f" }; # <<<<<<<<< With this it works!!!!
*x = $main::{ "_<$f" };
$x{ 3 } = { };
Run Code Online (Sandbox Code Playgroud)
断点开始起作用.(这适用于Perl 5.14.4)
为什么它以这种方式工作?
以前有报道:
perldebguts说:
- 每个哈希都
%{"_<$filename"}包含由行号键入的断点和操作.单个条目(与整个哈希相对)是可设置的.这意味着设置的断点
%{"_<..."}应用于指定的文件.实际上并非如此,因为每个%{"_<..."}散列都在行上设置断点@DB::dbline,而不管它引用哪个文件.假设是调试器将别名*DB::dbline来*{"_<..."}设置任何断点之前.因此,所有
%{"_<..."}哈希都是一样的.这是一个应该扩展文档以匹配实现的情况吗?或者我们应该更改实现以使每个
%{"_<..."}哈希在其相应的@{"_<..."}数组上工作?后者似乎对我更有用.
在5.20.0中,行为已更改,因此您不必使用别名@DB::dbline:
$ PERL5DB='
sub DB::DB {
($p,$f,$l) = caller;
print "$f:$l\n";
${"::_<$f"}{3} = 1; # no need for alias
$DB::single = 0
}
' perl -d foo
foo:1
foo:3
Run Code Online (Sandbox Code Playgroud)