I had an interesting glitch occur to me today. I had some code like

eval { for my $case ( @cases ) { if (!interesting($case)) { next; } process($case); } };

The problem was that both interesting() and process() would die for certain error cases. And instead of skipping all the cases on first error i wanted to see all the errors, so I changed to code to something like this:

for my $case ( @cases ) { eval { if (!interesting($case)) { next; } process($case); }; if ($@) { print "$case had errors:$@"; } }

I was a little surprised to discover that now all of my cases were failing. What took me a while to work out was that I had

use warnings FATAL=>'all';
in the code. Nexting out of an eval is a warning, and by promoting the warnings to a fatal the resulting behaviour of the code was fundamenetally changed.

So next time you decide to use warnings fatal do yourself a favour and do a code review of any evals that you are using. Heres an example of the issue.

#!perl -l $|++; use strict; use warnings; use warnings FATAL => 'all'; no warnings 'exiting'; # comment this out to change behaviour. { eval { next }; print "foo" } print "bar"; print "---"; for (1..10) { eval { print "bar"; next; print "foo"; }; print "Baz"; }
---
$world=~s/war/peace/g


In reply to Unexpected action at a distance with use warnings FATAL=>'all'; by demerphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.