Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: Memory issue with large cancer gene data structure

by ZWcarp (Beadle)
on Aug 08, 2013 at 15:29 UTC ( #1048589=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Memory issue with large cancer gene data structure
in thread Memory issue with large cancer gene data structure

Thanks again for your help. Would you mind explaining how this section is working?

# now remove double counted patients from the data structure foreach my $gene ( values %site_length_catch) { for my $count ( values %$gene ) { $count = keys %$count; # in scalar context you get the + number of keys

I get that you've created a hash of a hash of a hash $site_length_catch{$gene}{$sit}{$patient} = 1; and initialized the bottom value array to 1 ...correct? but then with this part how are you accessing the values of the next level... why would you use  values %site_length_catch instead of keys %site_length_catch

Thanks again for your time, the code works great, I just want to fully understand whats happening.


Comment on Re^4: Memory issue with large cancer gene data structure
Select or Download Code
Re^5: Memory issue with large cancer gene data structure
by hdb (Prior) on Aug 21, 2013 at 13:06 UTC

    Apologies for the late reply, I have been away for a while.

    To answer your question: keys iterates through the keys of a hash while values iterates through the associated values in the same order. So if you find you are writing code like:

    foreach my $key ( keys %hash ) { my $val = $hash{$key}; # do something with $val ... }

    and not use $key otherwise you can write directly

    foreach my $val ( values %hash ) { # do something with $val ... }

    If $val is a reference to a hash as in %site_length_catch, then %$val is a hash and the game can start again for the inner loop. The final line $count = keys %$count; takes the hash reference $count, counts its keys and overwrites the hash reference with the number of keys, in this case the number of patients.

    Hope this is helpful even if you have worked it out yourself already...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048589]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2014-12-28 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls