Why does this workaround for the internal Perl internal variable work?

t2.pl

1;
2;
3;

t.pl

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

When you run this code, you get HEREHERE, but the Perl magic variable does not work unless you use an alias with *dbline.

So, when you change the first two examples to look like this:

*dbline =  $main::{ "_<$f" }; # <<<<<<<<< With this it works!!!!
*x =  $main::{ "_<$f" };
$x{ 3 } =  { };

breakpoint starts to work. (This applies to Perl 5.14.4)

Why does it work this way?

Doc

+4
source share
1 answer

This has been reported before:

perldebguts says:

  • Each hash %{"_<$filename"}contains breakpoints and actions with line numbers. Individual entries (unlike the entire hash) are configurable.

, , %{"_<..."}, . , %{"_<..."} @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
+6
source

All Articles