CGI html table generation

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I've spent many years just bodging my html with the CGI module. But now
I'm trying to do it properly and I'm happy with my progress so far. What
I am having trouble with is specifying cell widths (and therefore the
width of the entire column).

I'm creating tables like this:

print table(,
    Tr({-align=>'left', -valign=>'top'},
        td([ "foo", "bar", "baz" ]),
        td([ "eenie", "meenie", "minee" ]),
        submit('Upload') . " or " . reset('Clear')

I used to set my widths with <td width="20%"> (or whatever value), but
I see that that method is now deprecated, and that we should use styles.
If that is the case, how does one, using the above table creation
method, add styles per table cell, because, from the above it appears
that cell attributes can be set only for the entire row by putting,
after "td(", {-attribute=>'setting', -other_attr=>'setting'}.

Thank you for any help you can give with this.


Justin C, by the sea.

Re: CGI html table generation

Quoted text here. Click to load it

      td({-style => 'width: 20%'}, [ "foo" ]);
      td({-style => 'width: 30%'}, [ "bar" ]);
      td({-style => 'width: 50%'}, [ "baz" ]);

Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg0cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.

Re: CGI html table generation

On 03/03/2010 13:16, Tad McClellan wrote:
Quoted text here. Click to load it

Ideally the styles would be specified in a separate CSS stylesheet
rather than embedded in the html markup.

I guess you need something like

   td({-class => 'productname'}, [ "foo" ]);
   td({-class => 'region'},      [ "bar" ]);

Apply the widths in your CSS stylesheet. E.g.

   td.productname { width: 20%; }


Personally, whilst the CGI module has it's uses, I've not found it very
useful for HTML generation. After all you are still mixing your Perl
code with HTML. Things that are arguable better separated by using a
templating approach. Automatic tag completion (i.e. enforcement of very
basic HTML syntax conformance) is the only benefit I see over something like

   print qq(<td class="productname">foo</td>);

The cost you pay for this benefit is the introduction of effectively a
third language. I've not been convinced it is worth it.

I do think is useful for handling the HTTP protocol, CGI
interface, decoding parameters etc.



Re: CGI html table generation

On Wed, 3 Mar 2010, RedGrittyBrick wrote:

Quoted text here. Click to load it

I thinks so, too. Another thing I consider very useful is setting default
values for a new iteration of a form to the last values given by the
end-user, thus allowing returning a partially incorrectly filled-out form
to the user for correction and completion. This feature, however, requires
that the pertinent HTML text is generated by the functions of the CGI
module. Other HTML text may be interspersed that is directly written to

Helmut Richter

Site Timeline