in reply to Re: Re: Problem with a hash of hashes
in thread Problem with a hash of hashes

OK, it looks like I may have guessed wrong about that -- sorry. (I don't see anything there that would cause the problem you described, that an element in the "%locations" hash of your calling routine seems to have an empty string as the hash key.

So when you run the first loop, with a reference to a non-empty array of keywords to search for, it works fine and you don't see any evidence of a bogus entry in the "%locations" hash. Then, when you do a second loop, with a reference to an empty array instead of a keyword list, you see the extra "$article" key that turns out to be an empty string instead of a hash ref.

Since it looks to me like the "process_article" sub is not changing anything in %locations, the next question would be: what happens between these two loops? Also, when you say that you print out all the keys in %locations "to make sure they're all there and they are", you should be looking for a key that is an empty string. To make this visible, you'd need to do something like:

print ":",join(":", keys %locations),":\n";
(If your keys include colon characters, use something else as a separator, e.g. "|".) If this print-out shows two separators in a row, you're looking at a hash element with an empty string as the hash key. In that case, you need to figure out where (and how many times) you are using an empty string to set or inspect an element of this hash array, before going into that second loop.

It may also be possible, the way the "process_article" logic is written, that you would only notice an empty string for $article when you happen to be doing a "chromosome search"; i.e. the empty hash key is there in both loops, and only causes trouble in the second one. But I'm just guessing about that.

Replies are listed 'Best First'.
Re: Re: Re: Re: Problem with a hash of hashes
by dannoura (Pilgrim) on Aug 08, 2003 at 05:00 UTC

    Thanks for taking the time, graff.

    As you suggested, I printed out the keys for %locations (with ":" as delimiter). There are 10 keys, none of them is an empty string and that doesn't change throughout the loop.

    I didn't mention before that I've also put the chromosome search before the keyword search. I get the same problem for the chromosome search only so I'm guessing it must be something to do with how I'm calling process_article.

    -----------------------------------

    Any comments about coding style are welcome.