Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Knowledge gained through abject stupidity

by 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...

my %globalHash; my @globalArray; # do stuff with %globalHash, and push a snapshot of it # periodically onto @globalArray. .... foreach my $hashRef ( @globalArray ) { my %localHash = %{$hashRef}; print $globalHash{"KeyOne"}; print $globalHash{"KeyTwo"}; ... }
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.

Replies are listed 'Best First'.
Re: Knowledge gained through abject stupidity
by lemming (Priest) on Feb 08, 2001 at 00:30 UTC

    I'll have to look up the author of this quote:
    "Experience is used to avoid mistakes, experience is gained through making mistakes."

    You can also gain knowledge by listening to others, but there's no substitute for being part of a burning, roll over crash.

(crazyinsomniac) Re: Knowledge gained through abject stupidity
by crazyinsomniac (Prior) on Feb 08, 2001 at 00:57 UTC
    I think it's excellent to be stupid, as long as your stupidity is evolving.

    People who truly learn from a flaming car crash, tend not to repeat their mistakes.

    "cRaZy is co01, but sometimes cRaZy is cRaZy".
                                                          - crazyinsomniac

      Ignorance, not Stupidity can be overcome.

      If you continue to make the same mistakes, you are starting to exhibit stupidity, and not ignorance. (btw: this is one of the reasons I despise the '...for Dummies' books.) If you learn after the first few mistakes, you are overcoming ignorance. And that is the true path to enlightenment.


      Always keep a song in your heart.
      It's like karaoke for the voices in your head.
        The title of the main thread is "Knowledge gained through abject stupidity".

        I made no mention of ignorance or overcoming Stupidity.

        DeusVult said, "printed out the contents of the other freakin' hash" which is not ignorance, but stupidity, abject stupidity.

         
        "Disclaimer: Don't blame, it came from inside the void"
        #--------------------------------------------- crazyinsomniac

Re: Knowledge gained through abject stupidity
by hotyopa (Scribe) on Feb 08, 2001 at 04:25 UTC
    "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein

    Ergo, there is plenty of scope for further learning!!

    *~-}hotyopa{-~*

      I'm gonna bungle it, but Frank Zappa's version goes something like "Physicists will tell you that hydrogen is the most common thing out there and is the building block of the universe. But I disagree, because there's a hell of a lot more stupidity out there than hydrogen"

      Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Re: Knowledge gained through abject stupidity
by jorg (Friar) on Feb 08, 2001 at 17:12 UTC
    Good to see other people have had sleepless nights trying to debug code, while all that needed fixing was their debug method hehe!!
    I've actually put 'Check your debug method' in my top 5 of things to do when i think i've found a 'bug'.

    Jorg

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://57040]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (None)
    As of 2024-04-25 04:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found