No such thing as a small change | |
PerlMonks |
Knowledge gained through abject stupidityby DeusVult (Scribe) |
on Feb 08, 2001 at 00:23 UTC ( [id://57040]=perlmeditation: print w/replies, xml ) | Need Help?? |
It is amazing to me how many times the most intractable problem is not caused by insufficent knowledge, or error in algorithmic design. No, the greatest culprit of all is Abject Stupidity. Fortunately, although the problems caused by stupidity are incredibly embarrassing, they can be quite educational. So I will swallow my pride, and share with you the story of my humbling idiocy.
Many of you have been following the ongoing saga described here and here. Many of you have been extremely helpful with your advice, and I thank you. Perlmonks is an endless supply of generosity and knowledge. (Brief summary for people to lazy to read the nodes: I had a globally declared hash, which I was pushing references of onto an array. To make sure each reference was unique, I copied it to an anonymous hash first. But when I went through the array, I found that all of the elements were identical, with the values of whatever was put into the global hash last) The strange thing was, after putting such generosity and knowledge to use, the problem remained! Try as I might to figure out the cause, I was beyond my knowledge. I tried asking vague questions, desperately fishing the brains of my fellow monks for a reason, any reason, why this might be happening. Do you want to know what I finally discovered to be the cause? Here is a brief code sample, see if you can find it... After all of that work, all of that brain-wracking, forehead-smacking, eye-straining, computer-cursing effort trying desperately to figure out why the last values of %globalHash were the ones held in each element of the array, what do I find? That there was nothing wrong at all with my array, or my calls to push, or my use of references, or anonymous hashes. What was my error? I looped through each hash reference on my array, dutifully dereferenced it, and promptly printed out the contents of the other freakin' hash! On all of the complex and difficult tasks, I had programmed perfectly. It was the print statement that I did wrong. There is a lesson in this, my fellow monks. When you've gone over a piece of code a dozen times searching for an error without finding it, when you've tried every variation of that code and still it fails in the exact same way, when you're absolutely positive that you're not doing anything wrong in that little scrap of code...you're probably right. It's a different little scrap of code that you're ignoring completely that is causing the problem. Also, always check your print statements. Thank you to everyone who helped me with this. And runrig, chromatic, yoda, and everyone else who warned me about the evils of global variables, just stop you're snickering! Just one more piece of knowledge gained through abject stupidity. Some people drink from the fountain of knowledge, others just gargle.
Back to
Meditations
|
|