Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: X, Y Table structure

by wind (Priest)
on May 10, 2011 at 17:30 UTC ( [id://904005]=note: print w/replies, xml ) Need Help??


in reply to X, Y Table structure

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";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://904005]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-04-24 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found