ikegami,
Thanks that was simple enough. I failed to mention that there are counts for the x and y chr. example:
#!/usr/bin/perl -w use strict; #open file open(my $in,"/Users/mgavibrathwaite/Desktop/CCDS.current.txt") or die +" Can't open file: $!"; #open out file open(OUT, ">/Users/mgavibrathwaite/Desktop/genesperchrcnt.txt"); # initialize the hash my %geneids=(); #open the file and push the info from the designated columns into it # remove header my $firstline = <$in>; chomp $firstline; while(<$in>){ chomp; # remove the newline character my @fields = split (/\t/); #extract the columns that we are interested in. # Populate the key value pairs of the hash with $gene and $id $geneids{$fields[2]} = $fields[0]; # initialize an array to store hash values my @chr; push @chr, $fields[0]; #count chromosome number which is the value in the hash $geneids{$fields[0]}++; next if $geneids{$fields[0]} > 1; } foreach my $geneid ( sort { $geneids{$a} <=> $geneids{$b} } keys %geneids ) { print OUT "Chromosome $geneid has $geneids{$geneid} genes\n"; } close($in); close(OUT); =cut Output Chromosome has X genes Chromosome KLHL13 has X genes Chromosome UTY has Y genes Chromosome SPIN2B has X genes Chromosome PIR has X genes Chromosome ADRBK2 has 22 genes Chromosome SLC2A11 has 22 genes Chromosome SELO has 22 genes Chromosome PIK3IP1 has 22 genes Chromosome 21 has 323 genes Chromosome 18 has 358 genes Chromosome 13 has 402 genes Chromosome 22 has 553 genes Chromosome 20 has 724 genes Chromosome 15 has 733 genes Chromosome 14 has 772 genes Chromosome 8 has 827 genes Chromosome 4 has 922 genes Chromosome 9 has 982 genes Chromosome 10 has 1007 genes Chromosome 16 has 1009 genes Chromosome X has 1045 genes Chromosome 5 has 1054 genes Chromosome 7 has 1137 genes Chromosome 12 has 1283 genes Chromosome 6 has 1298 genes Chromosome 3 has 1354 genes Chromosome 17 has 1412 genes Chromosome 11 has 1543 genes Chromosome 2 has 1624 genes Chromosome 19 has 1660 genes Chromosome 1 has 2611 genes

I am only interested in output that contains the "Chromosome "num/x/y" has "num" genes.
How can I accomplish that?
Thanks Ikegami!
DeepSpace

In reply to Re^2: how can I print my hash values once? by lomSpace
in thread how can I print my hash values once? 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.