Baz has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to use the Tr and td functions to produce the following html -
<tr> <td width="15%"><font color="888888"><strong>Tab Type</strong></font>< +/td> <td width="40%"><font color="ffffff">Song</font></td> <td width="25%"><font color="888888">Tabbed by</font></td> <td width="20%"><font color="ffffff" <center>Selections</center></td> </tr>
but i cant figure out how to get the td function to produce different widths.
The code below generates td tags with all widths = 25%
Td({width=>'25%'},$col[0],$col[1],$col[2],$col[3])
...can it be done, because Idd like to leave the days off spitting out lines of ugly html behind me; and is there a good tutorial or resourse anywhere that might help me to better understand the use of cgi.pm with respect to formatting my html.

Replies are listed 'Best First'.
Re: THe td and Tr functions of CGI.pm
by Masem (Monsignor) on Nov 18, 2001 at 20:37 UTC
    Unfortunately, there's no way using CGI.pm to do this alone (Though a module like HTML::TableLayout might be able to do it.).

    However, you can sorta clean up this code with:

    @widths = ( 15, 40, 25, 30 ); print map { td({width=>'$widths[$_]%'}, $col[$_] } (0..3);

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

Re: THe td and Tr functions of CGI.pm
by cLive ;-) (Prior) on Nov 18, 2001 at 22:13 UTC
    I remember being confused because the CGI.pm docs only go into *major* shortcuts for creating tables. But after a little thought, I got it to work like everything else does in the module...
    # assuming this... my $q = new CGI; # then use this print $q->Tr( $q->td({-width=>'15%'},$col[0]), $q->td({-width=>'40%'},$col[1]), $q->td({-width=>'25%'},$col[2]), $q->td({-width=>'30%'},$col[3]), );

    Of course, you may already know this and be looking for a shorter shortcut, but I just thought I'd check.

    cLive ;-)

(jeffa) Re: THe td and Tr functions of CGI.pm
by jeffa (Bishop) on Nov 18, 2001 at 21:30 UTC
    <plug shame="nada"> DBIx::XHTML_Table </plug>

    But, this might be a good time to start learning HTML::Template. ;)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)