in reply to Printing Error of Hash of Array

What "runtime errors" do you get?

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

    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!

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

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