in reply to In a hash with hashes

You're overwriting the hash value with each new patient. Try:

$practice = {}; foreach $patient(@{$self->{patient_details}}) { push @{ $practice->{ $patient->{suregery_id} } }, $patient; }

It creates an array of patients for each id.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

Replies are listed 'Best First'.
Re^2: In a hash with hashes
by AnomalousMonk (Archbishop) on Jan 10, 2010 at 21:57 UTC

    Since BrowserUk has already provided the answer, this reply is very much BTW, but FWIW...

    In the OPed code fragment, the statement
        $practice->{$patient->{suregery_id}} = \$patient;
    repeatedly assigns (i.e., overwrites) a reference to  $patient to the hash key  $patient->{suregery_id} of the hash referenced by  $practice.

    The OPed code iterates over an array of hash references, so  $patient is already a hash reference. The statement above repeatedly assigns the LHS hash element a reference to a reference to a hash, which is probably even less what weezer_316 wanted! (Again, not that it matters much at this point.)

Re^2: In a hash with hashes
by weezer_316 (Novice) on Jan 10, 2010 at 13:56 UTC

    The code is at work, I'm at home, but I think your a genius! Thats utterly obvious and ive totally missed it. Thanks alot!