in reply to Re^2: how to access hash key from the hash value when hash key is pointing to an array of hash values?
in thread how to access hash key from the hash value when hash key is pointing to an array of hash values?

One minor niggle, your results wording, "first found", implies some ordering in the hash which isn't there. Add some more data to the hash and you may well get a different "first found". If perhaps the taxon codes are all numeric and you said

... sort { $a <=> $b } keys %gg;

then the labelling would be more meaningful.

I hope this is of interest.

Cheers,

JohnGG

  • Comment on Re^3: how to access hash key from the hash value when hash key is pointing to an array of hash values?
  • Download Code

Replies are listed 'Best First'.
Re^4: how to access hash key from the hash value when hash key is pointing to an array of hash values?
by ikegami (Patriarch) on Jan 29, 2010 at 23:36 UTC

    One minor niggle, your results wording, "first found", implies some ordering in the hash which isn't there.

    That's not true. You are visiting the hash of arrays in some order. It might not be meaningful or static, but it's why you don't end up visiting the same node twice.

    The solution in question returns the first match encountered. It doesn't matter if the order will be different later, because you'd use it when you're expecting at most one match.

    Update: Additions to clarify

Re^4: how to access hash key from the hash value when hash key is pointing to an array of hash values?
by AnomalousMonk (Archbishop) on Jan 29, 2010 at 23:38 UTC

    We-elllll...

    Add some more data to the hash and you may well get a different "first found".

    Indeed, this is the case when searching for the  NP_025 gene in the example.

    I think the word 'first' has to be taken in the context of the word 'all' that is used in the example: "first taxon found containing the gene being searched for" versus "all taxons found containing the gene being searched for". Or something like that (waves hands). I would let the wording stand.