Your skill will accomplish
what the force of many cannot
Get stricter with use warnings FATAL => 'all';by toolic (Bishop)
|on Oct 12, 2011 at 14:29 UTC||Need Help??|
I suggest you switch to
to promote all warnings to errors and die immediately on the first warning (see Fatal Warnings).
Why you should use this
It is more effective at finding bugs in your code than plain old use warnings;.
It is a widely-regarded good Perl coding practice to add use warnings; to your code because you want perl to notify you of impending problems. In my experience, the warnings have always pointed to a bug in my code.
The issue is that, in some common usage scenarios, it is too easy to miss the warning messages unless you are looking for them. They can be hard to spot even if your code generates a small amount of output, not to mention anything that scrolls off the screen. Or, if your output (STDOUT and STDERR) is redirected to a log file which you typically do not look at, then you wouldn't see the warning messages. FATAL => 'all' will kill your program dead so that there is no way to miss the warnings. This is no different from use strict;, which dies immediately.
Although you may miss the warnings (without FATAL), there's a 100% chance your customers will see them. It's a little unprofessional looking if your code is spewing gobs of warning messages.
FATAL can also help prevent you from wasting your time if there are multiple warnings. Often times, the last warning is the most visible, but it's the first warning that you should target.
How do I start using this?Just add the line to your script template/boilerplate (or replace your existing use warnings; line). Any new code you create will have it. I've had this in place for a couple years now, and it took no time to adapt to the new level of strictness.
But some warnings really aren't important to me.You can always selectively disable warnings. It works just like warnings. Simply localize as you would normally:
Isn't this too strict?No. The reason you started using warnings in the first place was
toolic, you have no idea what you're talking about because...Please enlighten me if I have overlooked something. I see no downside; do you?
Updated: added direct link to fatal docs.