Warnings with CGI::Carp
The easiest thing you can do to alleviate warnings causing 500 errors in your CGI scripts is to use CGI::Carp. It places reasonable messages in the web server log file for troubleshooting and it has options for outputting actual errors in HTML.All you have to do to get it to work is "use CGI::Carp" with your other library includes.
Removing Local Warnings
There comes a time, however, when you don't have the option of adding CGI::Carp. I recently put together a script using WWW::Mechanize. Mech has a quiet mode that's easy enough to use, but it doesn't quite work as expected.Mech relies in part on some other libraries and it doesn't shut them all up. I ended up receiving warnings about input fields being outside form elements that I could not make go away. I tried "no warnings" declarations, but they still kept popping up - and besides, I didn't want to get rid of ALL the warnings - I just wanted to get rid of a certain subset of warnings that I knew were regularly occurring.
Enter an important line of code:


1<br /> 2local $^W = 0;<br />
What this does is it turns warnings off for a local code element - you can use it within a function or within an arbitrarily declared block.
In my case, it allowed me to turn off warnings specifically in an area of code that I knew was generating warnings that I did not want to see. This is a dangerous line if overused and it will not remove compile time warnings unless you place it within a BEGIN block. Perldoc has a good explanation of this in detail, along with other information about warnings so that you can produce the best solution for your problem.
Discuss Removing Local Warnings in Perl
