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

splain (W misc) You specified an odd number of elements to initialize a hash, which is odd, because hashes come in key/value pairs.

Replies are listed 'Best First'.
Re^4: Printing Error of Hash of Array
by snape (Pilgrim) on Feb 01, 2010 at 16:27 UTC

    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"; } } } }