It occurs to me that when you say, "I would like to create a hash where the gene is the key and the genotype is the value," you are actually describing a so-called "XY Problem." Because you then go on to say that what you really want is: "how many genes have a specific genotype."
I'm not going to write code for you now, but this indeed is the essence of Perl's "auto-vivification" feature. Because this will essentially allow you to write what you're looking for as $hash{$gene}{$genotype}++.
The data-structure that you actually need to solve your problem is a "hash of hashes," with the final target being an integer counter. At the end of the day, you want to have a first-level hash of genes, each bucket of which contains a hash of genomes, each bucket of which contains a count. Auto-vification wll take you there. If a first-level hash key (gene) does not exist, Perl will silently create it. Then, if the second level key (gene, genome) does not exist, Perl will repeat the favor.
Yes, the Perl language was not created by language-purists. It was created by people who had a job to do.
In reply to Re: Number of values for each key in hash
by Anonymous Monk
in thread Number of values for each key in hash
by Sofie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |