but how do I print the value from the 'good' key in the hash of hashes?Loop through the keys of the primary hash, and print out the 'good' values if 'good' keys exist:
use strict; use warnings; use Data::Dumper; my %clone_hash; while (<DATA>) { my ($key, $value) = split; my $grade = ($value =~ /^pass[1-3]$/) ? 'good' : 'bad'; $clone_hash{$key}{$grade}++; } #print Dumper(\%clone_hash); # Print out the 'good' keys for (keys %clone_hash) { print "$_ => $clone_hash{$_}{good}\n" if exists $clone_hash{$_}{go +od}; } __DATA__ Eif2b2 fail Eif2b2 pass5 Eif2b2 fail Eif2b2 pass2 Eif2b2 fail Eif2b2 pass4 Eif2b2 fail 49334 fail 49334 fail 49334 pass1 49334 fail 49334 pass4 Oxct1 pass4 Oxct1 fail Oxct1 pass4 Oxct1 fail
which prints:
Eif2b2 => 1 49334 => 1
In reply to Re^3: processing key value pairs of a hash
by toolic
in thread processing key value pairs of a hash
by lomSpace
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |