On Jan 18, 2008 6:06 PM, Kevin Viel <[EMAIL PROTECTED]> wrote: > This I cannot get my mind around... > > My data: > > SNP Genotype > 1 CC > 1 CT > 1 TT > 1 NN > > > It seems to me that I need a hash of hashes. > > Inner hash: > > $inner{ $Genotype }++ ; > > Since the value of the out hash ( $outer{ $SNP } ) has to be a scalar, this > scalar has to be a reference to the inner hash, correct? If so, how do I > declare them? > > my %outer ; snip
In general you only declare the outer hash. Perl uses some magic called autovivication to create the inner hash references. #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %data; #pick a better name while (<DATA>) { my ($snp, $genotype) = split; $data{$snp}{$genotype}++ } print Dumper(\%data); __DATA__ 1 CC 1 CT 1 TT 1 NN 2 CT 2 CT 2 CT -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/