Updated: Added few headers (thanks for the tip goes to artist). Added P.P.S. :)
Well, debugging techniques are vital for any developer. Bugs are everywhere and everyone comes across them in all different peices of software. You cannot do anything about it. What you can do though, is debug, fix and submit.
Intro
Unfortunately, I haven't seen much of the examples of good debugging sessions and had to learn that the hard way. Still learning... Whatever info I found was oversimplified and general. Let me share my knowledge in hope that everyone else will correct, add and beautify it and share their own. :)
First rule to follow is: "Work from top to bottom". Here, I consider the top of the system to be your program, which runs on top of something, which runs on top of something, which runs on top of something. Since that is the new program you are writing, it is obviously less tested then all those parts on which it runs, therefore, the chances are that your program contains bugs, that make your life misarable, and not the parts on which it runs. (That was one long sentense, wasn't it?).
Identify the problem
How to debug the problem? Well, that's a deep question. First, I'd say you need to identify the problem. Until you don't know exactly WHAT is wrong, you cannot fix it properly. Do some testing. Feed all sorts of different data onto the problematic part and see if you can find any patterns. That will help you to localize the problem.
Localize the problem
Problem localization is important since it narrows down your search and increases your success chances. Here, print statements and Data::Dumper module are your best friends. Usually, the problematic area is small, few lines of code. If it is all inside the same part of your program, you are a lucky guy. If the problem is between two or more components - the world is hard on you. :)
Understand the problematic piece of code
When you know where you problem is, reread and reunderstand the piece of code. Make sure that you know precisely what's going on. Still cannot see the bug? Go on... Take the piece of code completely outside of your program and work on it separately, without any context. You are lucky again if you can do that. :)
Is it time to learn perl's debugger?
If you still don't have it, maybe it's a time to use a debugger. Perl's built-in debugger is very nice. Go through a perldebug manual. That should help. With debugger, you can do lots of fancy staff like going through the program step by step, printing out variable values at each step, setting up breakpoints, etc. That should help.
Dive deep down
If you still have a problem and you still cannot see it, possible there is a problem in someone else's code, not yours. (surprise-surprise). First thing to check is the next level on which your program runs. Maybe that's a module from CPAN or perl itself. If that's a module, go through and check it out. Read modules documentation. Possibly, you are not using the module correctly. Whatever.
Reimplement in other language, maybe?
In case of perl, though it gets more complicated. One of the things I can suggest is try to translate your perl code into some other language (PHP/C/Java/whatever) and execute it. It should as close translation as possible. If you don't see the problem with other language, maybe that's perl. If you still see it, possibly, it's on the lower leve, like an operating system. And yes, that happens too.
Try another operating system..
Does your code produces the same problem on the other system? If it still does, the problem is above the operating system, obviously. :) Operating system specific debugging is a deep topic on its own. I'll just say that if you use Linux, then you can have a handful of tools like strace(1) and ltrace(1) which will help you get really down and below.
That's a long node already, isn't it? I'll cut right here. Almost here...
Few words on submitting bug fixes/reports
Few words on fixing and submitting. You cannot always fix the problem that you encounter. Ask for help. Ask other people to look into it. Each and every project, has it's own developer and user community. Find it with Goggle and ask those people. At least they might point you to the right direction.
If you can fix the bug you found, then I wish you to have a long and happy life. :) Check project documentation for tips on how to submit bugs and/or bug reports. You did a lot of work by now, don't let it be lost. Let people know.
If you get ignored
Sometimes, though, you might get into akward situation, when developers will refuse to accept your fix and will not aknowledge the problem. This, unfortunately, happens too. You still can add some good onto the world. Publish the problem description, solution description, and the patch onto YOUR OWN web site. People will find it, when it's needed.
Share the experience
Now, really last words. Share your debugging experience. Once in a while, document the problem you encountered and the way you found a solution for it. Let the others learn from your experience. Mention the tools you've been using. Suggest testing data. Whatever. There are not that many examples of these on the web, unfortunately. I don't have a good example for developer's debugging, but here is a nice page with Admin Horror Stories. It lays out things nicely.
P.S.: Ok, next time I'll use the "Read More" thingy and a spell-checker. :)
P.P.S: I haven't mentioned any of #!/usr/bin/perl -w and use strict; since I assume you already had them from the very beginning. :)
Leonid Mamtchenkov