Article
Attack of the Killer Bugs!
Page: 1 2
use warnings;
Another similar helpful tool is Perl's built-in warnings. Like the strict pragma, they give you advance warning of any quirks that might or might not be errors, but probably are. Again, just like with strict, you can add them to your program by just adding use warnings; to the top. The top of your code file should now look like this, provided that you want to add both strict and warnings.
#!/usr/bin/perl
# weather.pl by Perl F. Anatic
use strict;
use warnings;
But what exactly do these warnings do? They will show you your typing mistakes, for instance, if you try to use = instead of == in an if block, or you try to add a string to a number, like print "fish" + 4;. These might seem like silly mistakes, but they're really quite common. If you think about the errors you make when you're debugging, you will find that most of them are "stupid", and that you just weren't thinking right when you were coding that bit.
Wrapping It All Up
Debugging will always take more time than it should. Whether it takes you twice as much time as coding new features, or it takes you just a few seconds every week (lucky thing!), these tips will drastically reduce the time you spend being frustrated as you search for that errant mistake. With the tools that are available, you have no excuse to not use them!
For every mistake you make, think about how you could have prevented it as soon as you tested your code. Automate the bug fixing that can be automated. Let the Perl interpreter do the dirty work, and leave the tough problems and new features to us humans. Programming is about making software, not bugs!
Links
The use strict; documentation, visit http://perlmonks.org/index.pl?node=strict
For more information on use strict; and warnings, visit use strict; is not Perl and Use strict and warnings.