Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Programmatically generating HTML tables including <thead> and <tbody>

by andyford (Curate)
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
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
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

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2015-07-06 12:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls