http://www.perlmonks.org?node_id=569234

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

I'd like my CGI program to generate a table elegantly, but CGI.pm, HTML::Table, and Data::Table don't seem to make any provision for outputting the <thead> and <tbody> tags.
I.e., if I want to be doing something like this
print table( Tr(\@rows) );
I can't see how to slip the <thead> and <tbody> in there.
Has anyone any experience or tips on this?

andyford
or non-Perl: Andy Ford

  • Comment on Programmatically generating HTML tables including <thead> and <tbody>
  • Download Code

Replies are listed 'Best First'.
Re: Programmatically generating HTML tables including <thead> and <tbody>
by Cody Pendant (Prior) on Aug 24, 2006 at 00:59 UTC
    Works For Me:
    use CGI qw(:standard); my @headers = ( th('a'),th('b'),th('b'), ); my @row = ( td('1'),td('2'),td('3'), ); print table( thead( Tr( @headers ) ), tbody( Tr( @row ) ), );
    output:
    <table> <thead> <tr> <th> a </th> <th> b </th> <th> b </th> </tr> </thead> <tbody> <tr> <td> 1 </td> <td> 2 </td> <td> 3 </td> </tr> </tbody> </table>
    It's not a matter of slipping thead/tbody in, it's a matter of wrapping them around the outside.

    But as everyone else says I'd use templating instead.



    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print
Re: Programmatically generating HTML tables including <thead> and <tbody>
by revdiablo (Prior) on Aug 23, 2006 at 22:28 UTC

    This is one of the many reasons I like to use templates, rather than HTML-generating code routines. The output never quite matches what I want or expect. I'd recommend HTML::Template, but I know a lot of people are partial to Template Toolkit too.

Re: Programmatically generating HTML tables including <thead> and <tbody>
by imp (Priest) on Aug 23, 2006 at 22:29 UTC