How can I use Perl 5.10 features inside the debugger?

前端 未结 1 946
星月不相逢
星月不相逢 2021-02-19 18:28

I am unable to evaluate \'modern Perl\' code inside the Perl debugger. It works OK when debugging the code in a file, but not from the prompt.

Minimal example:

<         


        
1条回答
  •  一生所求
    2021-02-19 18:57

    I found a reference to the issue here, but it's about a year old. However, the relevant portion of the Perl source hasn't changed since and can be seen here. Essentially, if you take a look at toke.c in the Perl source, you see the following:

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

    Basically, the debugger is loaded before the -E flag is processed, so the features aren't yet enabled when the debugger gets loaded. The gist of this is that you can't currently use -E with the -d command. If you want to use say, switch, or any other feature from the debug prompt, you have to do it like this:

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

    The closest I've seen to a solution is:

    1. copy perl5db.pl from your PERL5LIB to either somewhere in PERL5LIB or the current directory, with a different name, say myperl5db.pl 2. Edit myperl5db.pl to have use feature ':5.10'; (or just 'state', or just 'say') on the first line. 3. Set the environment variable PERL5DB to "BEGIN { require 'myperl5db.pl' }"

    Which I found at PerlMonks.

    0 讨论(0)
提交回复
热议问题