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
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.use warnings FATAL=>'all';
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"; }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |