The way the HTML modifiers work in CGI.pm is that there are two 'arguments' to each HTML function:
TAG( <optional hash>, <scalar>|<array ref> )
Assuming that the optional hash exists, then these will
be used as tag attributes for the second argument, otherwise there will be no additional attributes. If the second argument is a scalar, then only one tag will be generated (with closure). On the other hand, if the second argument is an array ref, then a tag with the given attributes will be generated for each element in that array.
For example, to print a table row where each element is the same width, you can do:
print $cgi->table(
$cgi->Tr(
$cgi->td(-width=>"20%", [1,2,3,4,5])
)
);
However, you want to change the width. Unfortunately, to do this, you can't just simply use this format. Instead, you'll have to specify each td separately:
print $cgi->table(
$cgi->Tr( [
$cgi->td(-width=>"10%", 1 ),
$cgi->td(-width=>"20%", 2 ),
$cgi->td(-width=>"30%", 3 ),
$cgi->td(-width=>"20%", 4 ),
$cgi->td(-width=>"20%", 5 )
] )
);
There's numerous ways to improve this code with maps and other modules, but that's the simpliest way of do this. If this code gets too complicated, you may want to look at the various template modules (HTML::Template, HTML::Mason, Template Toolkit 2), which allow you to write the HTML for the table explicitly, then insert the values from your perl code dynamically.
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important
|