can you post your code so we can see/adjust what you're doing?
from scratch, here's a (untested) solution. Basically, instead of the concat building of a $row string, you map to loop over the cols, and also use
join. But first hash everything up.
my %all = ( p => {}, v => {} );
my %s;
foreach my $row ( @results ){
$all{p}->{ $row->{p_id} } = 1;
$all{v}->{ $row->{v_id} } = 1;
$s{ $row->{v_id} }->{ $row->{p_id} } = $row->{s_id};
}
my @p = sort keys %{$all{p}};
my @v = sort keys %{$all{v}};
print join("|", " ", map { sprintf(" p_%-2d ",$_) } @p ), "\n";
print "-"x(7*(@p+1)) . "\n";
foreach my $v ( @v ){
# note hash slice
print
join( "|", # delim
sprintf(" v_%-2d ",$v), # first column
map {
defined($_) ? sprintf(" s_%-2d ",$_) : " " # format acc
+ordingly
} @{$s{$v}}{ @p } # all the s values for the 'p' colum
+ns; done via a hash slice
),
"\n";
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.