in reply to printing out a matrix for a data list
You were well on your way, but the first two on this list can confuse things enough that you can't see the rest. That's the way it happens, it's the things you're not looking at that get you.
printsuse strict; my %table; my %rows_cols; my %cols; for(<DATA>) { chomp; my($row,$col,$val) = split ', *'; if ($row>$col) { ($row,$col) = ($col,$row); } $table{$row}{$col} = $val; $rows_cols{$row}++; $rows_cols{$col}++; } for my $col (sort keys %rows_cols) { print "\t$col"; } print "\n"; my $val; for my $row (sort keys %rows_cols) { print "$row\t"; for my $col (sort keys %rows_cols) { if (defined $table{$row}{$col}) { print $table{$row}{$col}; } elsif (defined $table{$col}{$row}) { print $table{$col}{$row}; } else { print "-"; } print "\t"; } print "\n"; } __END__ ob1, ob2, 34 ob1, ob3, 56 ob1, ob4, 12 ob1, ob5, 78 ob1, ob6, 23 ob3, ob1, 56 ob7, ob1, 23 ob8, ob1, 12 ob9, ob1, 90 ob3, ob2, 87
ob1 ob2 ob3 ob4 ob5 ob6 ob7 ob8 + ob9 ob1 - 34 56 12 78 23 23 12 + 90 ob2 34 - 87 - - - - - + - ob3 56 87 - - - - - - + - ob4 12 - - - - - - - + - ob5 78 - - - - - - - + - ob6 23 - - - - - - - + - ob7 23 - - - - - - - + - ob8 12 - - - - - - - + - ob9 90 - - - - - - - + -
|
|---|