Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  
and by andyford (Curate)

Programmatically generating HTML tables including

on Aug 23, 2006 at 22:20 UTC ( #569234=perlquestion: print w/replies, xml ) Need Help??
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://569234]
Approved by GrandFather
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2017-01-20 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (173 votes). Check out past polls.