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.


In reply to Re: Re: Re: Problem with a hash of hashes by graff
in thread Problem with a hash of hashes by dannoura

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.