Just off the top:
foreach (@stuff) { my ($a,$b,@stuff) = split (/:/); push (@{$data{$a}{$b}}, @stuff); }
Or, if you are working with unique A:B pairs, you could do something like this:
foreach (@stuff) { my ($a,$b,@stuff) = split (/:/); $data{$a}{$b} = [ @stuff ]; }
Whatever method you choose to put the stuff in there, you are going to have to get it out. The tricky part is figuring out how big your grid is, no? If each row can have holes, you are going to have to find all possible columns up front, like so:
my %column_width; foreach my $row (keys %data) { foreach my $column (keys %{$data{$row}}) { my $data_length = length($data{$row}{$column}); if (!exists($column_width{$column}) { # Make sure the label fits $column_width{$column} = length($column); } if ($column_width{$column} < $data_length) { $column_width{$column} = $data_length; } } } # Order the columns accordingly. You may need a better sort. my @columns = sort keys %column_width; print join (" | ", sprintf ("%15s", ""), map { sprintf ("%*s", $column_width{$_}, $_) } @columns; ),"\n"; foreach my $row (sort keys %data) { my $continued; my $line = 0; do { $continued = 0; print join (" | ", # Only title the first line (0th) sprintf ("%15s", $line? '' : $row), map { $continued++ if (defined($data{$row}{$_}[$line+1] +)); sprintf ("%*s", $column_width{$_}, defined($data{$row}{$_}[$line])? $data{$row}{$_}[$line] : ''); } @columns ), "\n"; $line++; } while ($continued); }
For simplicity, I have chosen 15 as an arbitrary width. It is trivial to calculate this, as has been done for each column.

Testing and debugging, as they say, is left as an exercise for the reader.

In reply to Re: Changing the way data is formatted, a three year conundrum by tadman
in thread Changing the way data is formatted, a three year conundrum by krujos

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.