use strict;
use warnings;
my %table;
my %sizes;
for (
# SELECT qty, size, price
[ 100, 1, 43 ],
[ 250, 1, 52 ],
[ 100, 2, 45 ],
[ 250, 2, 55 ],
[ 100, 3, 50 ],
[ 250, 3, 56 ],
[ 200, 4, 55 ],
[ 250, 5, 61 ],
) {
my ($qty, $size, $price) = @$_;
$table{$qty}{$size} = $price;
$sizes{$size} = 1;
}
my @sizes = sort {$a <=> $b} keys %sizes;
print '<table>', "\n";
print '<tr>';
print '<th> </th>';
print '<th colspan=' . @sizes . '>Sizes</th>';
print '</tr>', "\n";
print '<tr>';
print '<th>QTY</th>';
for my $size (@sizes) {
print "<th>$size</th>";
}
for my $qty (sort { $a <=> $b } keys %table) {
print '<tr>';
print "<th>$qty</th>";
for my $size (@sizes) {
print '<td>', (defined $table{$qty}{$size} ? "\$$table{$qty}{$si
+ze}" : ' '), '</td>';
}
print '</tr>', "\n";
}
print '</table>', "\n";