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

I am getting the following error:

Odd number of elements in anonymous hash

Update: I found the mistake and posted the working code on Re^4 (below) Thanks!

Replies are listed 'Best First'.
Re^3: Printing Error of Hash of Array
by Corion (Patriarch) on Feb 01, 2010 at 15:04 UTC

    So, where in the code you posted is line 105?

Re^3: Printing Error of Hash of Array
by Anonymous Monk on Feb 01, 2010 at 15:16 UTC
    splain (W misc) You specified an odd number of elements to initialize a hash, which is odd, because hashes come in key/value pairs.

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