Hi I have file containing two columns, Genes and Genetype. I would like to create a hash where the gene is the key and the genotype is the value. I then would like to count and print out how many genes have a specific genotype. So for example: CECR1 protein_coding IKBKGP1 pseudogene ADA protein_coding I would like to have an output: protein_coding 2 pseudogene 1 I have come this far:
#open the textfile GeneType.txt open (GENETYPE, "GeneType.txt") or die "Could not open file"; while (<GENETYPE>){ ($GeneName, $GeneType)= split (/\t/, $_); $GeneHash{$GeneName} = $GeneType; #create hash my $scalar = delete $GeneHash{GeneName}; #removes the first line w +hich is a header print (each %GeneHash); #printing out the has just as a check
I am guessing I should use a for or foreach loop to iterate over the hash, but can't understand how. Thanks /beginner

In reply to Number of values for each key in hash by Sofie

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.