Hello!
I have a file that I have split and put into a hash and sorted based on the keys. Example:

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
For each key name/id, I want to do the following:
1. Count keys with no values above pass4 (pass1 to 3 are fine, 4 to fail are bad).
2. Count the keys which after excluding pass4 to fail have only one key value pair.

Using the above example, the key 'Eif2b2' would have only 1 value below pass4,
that value would be 'pass2', and the key '49334' would have 1 value below 'pass4', 'pass1'.
The total for keys with no values above pass4 would be two.
The next count would be two also, because after each value, for the above mentioned keys, there would be one value remaining after removing everything above 'pass4'. Here is my code:
#!/usr/bin/perl -w use strict; use warnings; open( my $in, "c:/Documents and Settings/mydir/Desktop/current/mart_ex +port.txt" ); open( my $out, ">c:/Documents and Settings/mydir/Desktop/current/mart_ +export_counts.txt" ); my $first_line = <$in>; chomp $first_line; my %clone_hash; while (<$in>) { chomp; my @fields = split /\t/; my ($gene_symbol, $esc_qc, $qc_id) = ($fields[1], $fields[8], $fie +lds[9]); #my $count = 0; #my $clone1 = 0; $clone_hash{$gene_symbol} = $esc_qc; } # sort the oligos by gene_symbol my @sorted_keys = sort { $a <=> $b || $b cmp $a } keys %clone_hash; foreach my $key (@sorted_keys) { print $out "$key = $clone_hash{$key}\n"; } close ($in); close ($out);
I would appreciate the monks direction.

In reply to processing key value pairs of a hash by lomSpace

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.