Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Printing out multiple hashes at one time

by roboticus (Chancellor)
on Dec 19, 2012 at 20:14 UTC ( #1009625=note: print w/ replies, xml ) Need Help??


in reply to Printing out multiple hashes at one time

cvillain:

If you'd fix some of the messages that strict and warnings give you, it might simplify things. But as far as your question: Yes you can scan through the keys and print them like this:

for my $penta (keys %totalProbability) { print "$totalProbability{$penta}, $totalCounts{$penta}, ...\n"; }

However, the reason I replied is to mention this: You'd do yourself a favor if you build the statistics data you need as you read it. Something like:

my %stats; while (<FREQ>) { chomp; my ($pent, $pentExpected, $pentObserved, $pentTotal) = split("\t", +$_); next if !defined $pentTotal; # skip malformed lines and end line my $h = { pent=>$pent, count=>$pentObserved, prob=>$pentExpected, pentTotal=>$pentTotal }; push @data,$h; if (exists $stats{$pent}) { $stats{$pent} = { probTotal => $$h{prob}, countTotal => $$h{count}, pentTotal => $$h{pentTotal}, }; } else { $stats{$pent}{probTotal} += $$h{prob}; $stats{$pent}{countTotal} += $$h{count}; $stats{$pent}{pentTotal} += $$h{pentTotal}; } }

roboticus

When your only tool is a hammer, all problems look like your thumb.


Comment on Re: Printing out multiple hashes at one time
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2015-07-28 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls