为什么magic Perl内部变量的这种变通方法有效? t2.pl t、 pl

为什么magic Perl内部变量的这种变通方法有效? t2.pl t、 pl,perl,debugging,Perl,Debugging,当您运行此代码时,这里会出现,但如果您不使用*dbline对magic Perl变量进行别名,则该变量无效 因此,当您将前两个示例更改为: PERL5DB="BEGIN{ require 't.pl' }" perl -d t2.pl *dbline=$main::{“\up>这是以前的: perldebguts说: 每个hash%{“\u所有三个都是从5.20开始工作的,${”main::\u看起来像一个bug。我可以在5.16.3中重现这个问题,但不能在5.22.1中重现。 packag

当您运行此代码时,这里会出现
,但如果您不使用
*dbline
对magic Perl变量进行别名,则该变量无效

因此,当您将前两个示例更改为:

PERL5DB="BEGIN{ require 't.pl' }" perl -d t2.pl
*dbline=$main::{“\up>这是以前的:

perldebguts说:


  • 每个hash
    %{“\u所有三个都是从5.20开始工作的,
    ${”main::\u看起来像一个bug。我可以在5.16.3中重现这个问题,但不能在5.22.1中重现。
    
    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;
    
    PERL5DB="BEGIN{ require 't.pl' }" perl -d t2.pl
    
    *dbline =  $main::{ "_<$f" }; # <<<<<<<<< With this it works!!!!
    *x =  $main::{ "_<$f" };
    $x{ 3 } =  { };
    
    $ 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