in reply to Number of values for each key in hash
The link provided by hippo seems a good place to start and the correspondence to your case can be deduced by:
($GeneName, $GeneType)= split (/\t/, $_); # your program my ($ip, $size) = split /:/; # the other program
Once you practice building and searching the hash, consider this:
I mentioned this because in your case I think the key should be the genotype (and not the genename) and the value should be an array of gene names.
Also, my $scalar = delete $GeneHash{GeneName}; will remove the genename you just added to your hash! You will end up with nothing. You probably wanted to skip the first line of the file. And do that just once, i.e. before the loop, like open (GENETYPE, "GeneType.txt") or die "Could not open file"; my $header = <GENETYPE>; which skips the first line of the file and saved it in that variable.
Finally, shouldn't print (each %GeneHash); be outside the file-reading-hash-generation loop? And this would do just fine: while( my ($k,$v) = each %GeneHash ){ print "$k=>$v\n"; }
Having said all these, and you going through them in order to get some experience, I want to mention the existence of BioPerl which is especially designed for bio-informatics and does tasks like yours pretty well, here is something relevant: https://bioperl.org/howtos/Beginners_HOWTO.html#item19 . But even with BioPerl you will need to know your hashes.
bw, bliako
|
|---|