Dear Monkers: I am trying to input the following file
AA SET1 0
AA SET2 1
AA SET3 0
BB SET1 0
BB SET3 0
CC SET1 2
CC SET2 3
and print the following
NAME SET1 SET2 SET3
AA 0 1 0
BB 0 0
CC 2 3
My questions is that I am not able to get the right format for the output that I want. I created a 2D hash but got confused when I tried to print using "foreach". I have just started to learn perl and having trouble with printing hashes
%hashname = (); %hashlow = (); %hashhigh = (); open(INPUTL,"<$listfile") || die "Can't open \$listfile for reading.\n +"; while($line=<INPUTL>){ chomp $line; @toks = split(/\t/, $line); $dataset = $toks[0]; $gene = $toks[1]; $hashname{$dataset} = $dataset; $hashlow{$gene}{$dataset} = $toks[2]." ($toks[4])"; $hashhigh{$gene}{$dataset} = $toks[3]." ($toks[4])"; } close(INPUTL); foreach $gene (sort keys %hashlow){ if ($gene =~ /AA/){ foreach $set (sort keys %{$hashlow{$gene}}){ print OUTD2 NAME."\t".$set; } } } print "\n"; foreach $gene (sort keys %hashlow){ print OUTD2 $gene."\t"; foreach $set (sort keys %{$hashlow{$gene}}){ print OUTD2 $hashlow{$gene}{$set}."\t"; } print OUTD2 "\n"; }
In reply to Using 2d hash to print a matrix by angerusso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |