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

Hi Monks, I have been playing with tables and I find it very difficult. Can someone show me an example to have nested tables using object oriented way for CGI.pm? In addition , say this is my sample code. This there a way I can put foreach statements so I can create as many rows / columns i want? I been hard coding a lot of table code for the more complex tables like using colspan and having dynamic tables.
print $q->table ({ -border=>"1", -width=>"100%", -cellSpacing=>"0", -cellPadding=>"3"}, Tr(td({-class=>'TXT1TABLE',-bgcolor=>"$GLOB_WEBPAGECOLOUR +S{BG1}"},\@HEADERNAMES)) , Tr(td({-class=>'TXT2TABLE',-bgcolor=>"$GLOB_WEBPAGECOLOUR +S{BG2}"},\@HEADERDATA)));

Replies are listed 'Best First'.
Re: Perl/CGI : need tips with tables within CGI.pm
by Cody Pendant (Prior) on Jan 14, 2005 at 01:41 UTC
    I apologise in advance for not helping you with your actual question, but I would say that's a really good case for using HTML::Template instead of CGI.pm.

    Your foreach loops would build up a data structure, rather than printing out, then pass the data structure to HTML::Template, which would handle the tables and the tables-within-tables as loops.



    ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
    =~y~b-v~a-z~s; print
Re: Perl/CGI : need tips with tables within CGI.pm
by talexb (Chancellor) on Jan 14, 2005 at 04:46 UTC

    I have to agree with the previous poster -- as soon as I saw your title, I thought, "Hmm, this sounds like a job for Template::Toolkit".

    OK, having got that off my chest, exactly what is the structure you want to do? Is it going to be a table, each of whose cells contains another table?

    Finally, why are you specifying a bgcolor (background colour for those not familiar) when you're also specifying a CSS class? Just curious.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      i'm very new to CSS. Thanks for telling me that i could take the bgcolor into the class. = )

        No problem. I highly recommend you purchase and read O'Reilly's CSS book .. it explains the whole concept very well, and, as usual, has great examples. Once you get your head around that, using something like Template::Toolkit and CSS means your formatting stays in CSS and the templates, your data access is handled within modules and the CGI just implements a little logic then ties together the data with the template.

        This is orders of magnitude better than trying to use the intellectually challenging CGI bits and the various DBI pieces all in one's Perl/CGI script. I'm now using CGI::Application so as to write as little code as possible, and when I get around to using Class::DBI, that should reduce my code even more. Simplify, simplify, simplify!

        Alex / talexb / Toronto

        "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: Perl/CGI : need tips with tables within CGI.pm
by neilwatson (Priest) on Jan 14, 2005 at 14:51 UTC
    A little off topic. Embedded tables are really nasty. Using CSS, such layout nightmares can be avoided.

    Neil Watson
    watson-wilson.ca

      can you give me examples of where CSS can be used to manipulate tables? I am new to CSS.
        The object is to use CSS to replace tables, not manipulate them. For example, most of the layout here at perlmonks can be done with CSS. Google is your friend.

        Neil Watson
        watson-wilson.ca