in reply to warnings under the debugger

Could it be because the debugger evals its input rather than submitting directly to Perl?

Update: ... and notwithstanding the, erm, confident reply below, I can now suggest this demo:

unixhost> # case 1 without eval unixhost> perl -ew '$foo = { bar => () };' Name "main::foo" used only once: possible typo at -e line 2. Odd number of elements in hash assignment at -e line 2. unixhost> unixhost> # case 2 - now "protect it" with eval ... unixhost> perl -ew 'eval "$foo = { bar => () };";' unixhost> unixhost> # nothing!

-M

Free your mind

Replies are listed 'Best First'.
Re^2: warnings under the debugger
by almut (Canon) on Mar 08, 2007 at 16:38 UTC
    unixhost> perl -ew 'eval "$foo = { bar => () };";'

    If I use -we instead of -ew, I do get the warnings with eval, too...

    $ perl -we 'eval "$foo = { bar => () };";' Name "main::foo" used only once: possible typo at -e line 1. Use of uninitialized value in concatenation (.) or string at -e line 1 +.

    (I figure that with -ew, the program is just the bareword "w", which is being passed the rest of the commandline as arguments :)

Re^2: warnings under the debugger
by Moron (Curate) on Mar 08, 2007 at 16:55 UTC
    Therefore I am still suggesting that an explanation for the symptoms is that, to use Anno's words, the debugger "starts a new interpreter each time ..." ... it reads the keyboard input and uses "string eval" on it instead of submitting it directly to Perl.

    -M

    Free your mind

      When I tried it (I don't use the debugger normally), I found that the warning is shown, if warnings are switched on. Here is a (slightly edited) session:
      anno@oliva> perl -wd -e '' Loading DB routines from perl5db.pl version 1.28 [...] DB<1> $x = { 1 } Odd number of elements in anonymous hash at (eval 10)[/usr/local/lib/p +erl5/5.8.7/perl5db.pl:628] line 2. [...]
      So it seems the debugger has ways of restoring the warning state of the outer interpreter in an eval. (Can't be that hard). Why the original poster didn't see the warning remains an open question.

      Anno

        Yes, I see your point. I think it's because -w (which you used in your test) makes the debugger eval with warnings as well whereas -Mwarnings (which the OP used instead) loads the warnings pragma as if it were explicitly loaded for the code being debugged while leaving the debugger's own separate interpreter instance unaffected.

        -M

        Free your mind

Re^2: warnings under the debugger
by Anno (Deacon) on Mar 08, 2007 at 16:39 UTC
    Well, that's string eval, which starts a new interpreter with warnings switched off to begin with. Technically you are correct, string eval has a radical effect on warnings :)

    What I meant to say is that a warning that is generated inside an eval (of any type) will be shown. Warnings are not suppressed by eval in a similar way die is.

    perl -we 'eval "use warnings; $foo = { bar => () };";
    will print the warning, even from within eval.

    Anno

Re^2: warnings under the debugger
by Anno (Deacon) on Mar 08, 2007 at 14:40 UTC
    eval has no effect on warnings.

    Anno