Try the code below. The changes include

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.

use 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
prints
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 - - - - - - - + -

In reply to Re: printing out a matrix for a data list by rodion
in thread printing out a matrix for a data list by Angharad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.