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


In reply to Re: Tables in CGI.pm by Masem
in thread Tables in CGI.pm by liquidc00l

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.