How can I use Perl 5.10 features inside the debugger?
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:
# Act开发者_运维问答ivating 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";
(Note: the same happens with "use feature ':5.10'".)
Am I missing something?
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:
- 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.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论