in reply to processing key value pairs of a hash

The code sample you provide doesn't match the sample data you provide and you don't show the expected output for the sample data so the following is rather a guess:

use strict; use warnings; my %clone_hash; while (<DATA>) { chomp; next if ! length; my ($gene_symbol, $esc_qc) = split /\s+/; $clone_hash{$gene_symbol}{$esc_qc}++; } my $okGenes = 0; my $singleOks = 0; foreach my $key (sort keys %clone_hash) { my $gene = $clone_hash{$key}; my $okPasses = grep {defined} @{{%$gene}}{qw(pass1 pass2 pass3)}; my $badPasses = keys (%$gene) - $okPasses; if ($badPasses) { ++$singleOks if $okPasses == 1; } else { ++$okGenes; } } print "Ok genes: $okGenes\n"; print "Single pass genes: $singleOks\n"; __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

Prints:

Ok genes: 0 Single pass genes: 2

True laziness is hard work

Replies are listed 'Best First'.
Re^2: processing key value pairs of a hash
by lomSpace (Scribe) on Apr 15, 2009 at 15:02 UTC
    Hi GrandFather!
    I actually split a file and used the fields to populate the hash
    that I declared outside the while loop. My output is
    "gene name \t #good clones "

    Thanks for the direction!
    LomSpace