代码之家  ›  专栏  ›  技术社区  ›  Pablo Marin-Garcia

如何在调试器中使用Perl5.10特性?

  •  12
  • Pablo Marin-Garcia  · 技术社区  · 15 年前

    我无法在Perl调试器中计算“现代Perl”代码。在调试文件中的代码时,它可以正常工作,但在提示符下则不行。

    # Activating 5-10 features with -E (it works)
    $  perl -E 'say "x"'
    x
    
    # 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";
    

    我错过什么了吗?

    1 回复  |  直到 4 年前
        1
  •  7
  •   Peter Mortensen icecrime    4 年前

    我找到了这个问题的参考资料 here ,但大约有一年了。然而,Perl源代码的相关部分自那以后就没有改变,可以看到 here toke.c 在Perl源代码中,可以看到以下内容:

    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) "';");
    

    基本上,调试器是加载的 之前 -E 标记已处理,因此在加载调试器时尚未启用这些功能。要点是你现在不能使用 -电子 -d say switch

      DB<1> use feature 'say'; say "x"
      x
    

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

    1. 复制perl5配电盘从PERL5LIB到PERL5LIB或当前目录的某个地方,使用不同的名称,比如myperl5配电盘 2编辑myperl5配电盘在第一行有use feature“:5.10”;(或者仅仅是“state”,或者仅仅是“say”)。

    我在 PerlMonks .