in reply to Re^2: processing key value pairs of a hash
in thread processing key value pairs of a hash
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: processing key value pairs of a hash
by lomSpace (Scribe) on Apr 15, 2009 at 16:45 UTC | |
|
Re^4: processing key value pairs of a hash
by lomSpace (Scribe) on Apr 15, 2009 at 18:42 UTC | |
by toolic (Bishop) on Apr 15, 2009 at 19:27 UTC | |
by lomSpace (Scribe) on Apr 16, 2009 at 13:28 UTC |