in reply to Re^3: Printing Error of Hash of Array
in thread Printing Error of Hash of Array

Thanks a lot. I found my mistake. The updated code for sorting the sum and then printing the ids as well as the column values too is as follows:

sub sort { my ($INPUT, $OUT) = @_; my %data; while (<$INPUT>) { next if (/^I|A|M/); chomp; my ($id,@cols) = split ('\t',$_); push @{$data{$id}}, \@cols; } my %hash; my $arrrow; my @arrcol; for my $key (keys %data){ for my $aref(@{$data{$key}}){ my $sum = sum(@{$aref}); my @col = @$aref; push @{$hash{$sum}{$key}}, \@col; } } for my $sum (sort keys %hash){ for my $key(sort keys %{$hash{$sum}}){ for my $val (@{$hash{$sum}{$key}}){ print $OUT "$key\t$sum\t@{$val}\n"; } } } }