in reply to Table manipulation, array or hash?

You are part way there. But really what you want is a hash of hash of arrays. Consider:

use strict; use warnings; my %data; while (<DATA>) { chomp; my ($snp, $ind, @parts) = split; next if @parts < 2; $data{$ind}{$snp} = \@parts; } for my $ind (sort keys %data) { print "$ind"; for my $snp (sort keys %{$data{$ind}}) { my $parts = $data{$ind}{$snp}; print "\t$parts->[0]\t$parts->[1]"; } print "\n"; } __DATA__ SNP5 IND1 A5 C5 0.8 SNP2 IND1 A2 C2 0.8 SNP1 IND1 A1 C1 0.8 SNP3 IND1 A3 C3 0.8 SNP4 IND1 A4 C4 0.8 SNP5 IND2 G5 T5 0.8 SNP2 IND2 G2 T2 0.8 SNP1 IND2 G1 T1 0.8 SNP3 IND2 G3 T3 0.8 SNP4 IND2 G4 T4 0.8

Prints:

IND1 A1 C1 A2 C2 A3 C3 A4 C4 A5 C5 IND2 G1 T1 G2 T2 G3 T3 G4 T4 G5 T5

True laziness is hard work

Replies are listed 'Best First'.
Re^2: Table manipulation, array or hash?
by robertkraus (Novice) on Mar 23, 2010 at 11:30 UTC
    Amazing! I was sitting over this already for 3 days or so (not really full time, but msot of the work day actually), and here the solution comes in a few mintues! I adopted it to implement into my workflow and it works like a dream, thanks a lot!