如何在调试器中使用perl 5.10功能?

Pab*_*cia 12 perl

我无法在perl调试器中评估"现代perl"代码.在调试文件中的代码时,它可以正常工作,但不能从提示中调试.

最小的例子:

# activating 5-10 features with -E (it works)
$  perl -E 'say "x"'
x
Run Code Online (Sandbox Code Playgroud)
# calling the debugger with -E
# it works for infile code but for prompt line code...
$  perl -dEbug    Loading DB routines from perl5db.pl version 1.33
    DB say "x"
    String found where operator expected at (eval 16)[/local-perl/lib/5.12.1/perl5db.pl:638] line 2, near "say "x""
    at (eval 16)[/local-perl/lib/5.12.1/perl5db.pl:638] line 2
        eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main; $^D = $^D | $DB::db_stop;say "x";

[注意:"使用功能"也是如此:5.10'"]

我错过了什么吗?

eld*_*his 7

这是一个有趣的问题,也是我从未想过的问题,因此对此表示赞赏.

我在这里找到了这个问题的参考,但它已经有一年了.但是,perl源的相关部分从那以后没有改变,可以在这里看到.基本上,如果你看一下toke.cperl源代码,你会看到以下内容:

if (PL_perldb) {
    /* Generate a string of Perl code to load the debugger.
     * If PERL5DB is set, it will return the contents of that,
     * otherwise a compile-time require of perl5db.pl.  */

    const char * const pdb = PerlEnv_getenv("PERL5DB");
            ...
}
...
if (PL_minus_E)
    sv_catpvs(PL_linestr,
          "use feature ':5." STRINGIFY(PERL_VERSION) "';");
Run Code Online (Sandbox Code Playgroud)

基本上,调试器加载之前-E处理标志,所以当调试器被加载尚未启用的功能.其中的要点是您目前无法使用-E-d命令.如果要使用say,switch或调试提示中的任何其他功能,您必须这样做:

  DB<1> use feature 'say'; say "x"
  x
Run Code Online (Sandbox Code Playgroud)

我见过最接近解决方案的是:

  1. 将perl5db.pl从PERL5LIB复制到PERL5LIB或当前目录中的某个位置,使用不同的名称,例如myperl5db.pl
  2. 编辑myperl5db.pl以使用':5.10'; (或只是'州',或只是'说')在第一行.
  3. 将环境变量PERL5DB设置为"BEGIN {require'myperl5db.pl'}"

我在PerlMonks找到了.