> -----Original Message----- > From: Chas. Owens [mailto:[EMAIL PROTECTED] > Sent: Monday, January 21, 2008 1:11 PM > To: Kevin Viel > Cc: beginners@perl.org > Subject: Re: Hash of hashes?
<snipped> > #! /usr/bin/perl > > use strict; > use warnings; > > use Data::Dumper; > > #this needs a better more descriptive name #maybe > %alleles_by_snp, I don't know your #domain well enough to > make a better suggestion my %outer; while ( <DATA> ) { > my ($snp, $genotype) = split; > $outer{$snp}{$_}++ for $genotype =~ /(.)/g; } > > for my $snp (sort keys %outer) { > my $count = keys %{$outer{$snp}}; > my $total; > $total += $outer{$snp}{$_} for keys %{$outer{$snp}}; > print "snp $snp has $count different alleles and a > total of $total\n"; } > > __DATA__ > 1 CC > 1 CT > 1 TT > 1 NN > 2 CC Great! One of the keys to my uderstanding of this is the use of %{}. I believe my mistake was that the piece inside should be the scalar (reference) of usual or uncomplicated fashion, i.e. $outer{ $snp }. You placed another little gem in here for me to digest: > $outer{$snp}{$_}++ for $genotype =~ /(.)/g; } I guess when I conceive of that by myself, I should move to the intermediate mailing list :) Many kind thanks, Kevin Kevin Viel, PhD Post-doctoral fellow Department of Genetics Southwest Foundation for Biomedical Research San Antonio, TX 78227 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/