in reply to Sending data for LOOP in HTML::Template
use HTML::Template; my @data = ( [ qw/a0 a1 a2 a3 a4 a5/ ], [ qw/b0 b1 b2 b3 b4 b5/ ], [ qw/c0 c1 c2 c3 c4 c5/ ], [ qw/d0 d1 d2 d3 d4 d5/ ] ); my @col_name = qw/ col0 col1 col2 col3 col4 col5 /; my @selection = (1, 4, 5); my $tmpl = HTML::Template->new( filehandle => \*DATA ); my @headers = map {{ title => $_ }} @col_name[ @selection ]; my @rows = map {{ cols => [ map {{ data => $_ }} @$_[ @selection ] +] }} @data; $tmpl->param( headers => \@headers, rows => \@rows ); print $tmpl->output; __DATA__ <table border=1> <tr> <TMPL_LOOP headers><th><TMPL_VAR title></th></TMPL_LOOP> </tr> <TMPL_LOOP rows> <tr> <TMPL_LOOP cols><td><TMPL_VAR data></td></TMPL_LOOP> </tr> </TMPL_LOOP> </table>
which produces this output:
| col1 | col4 | col5 |
|---|---|---|
| a1 | a4 | a5 |
| b1 | b4 | b5 |
| c1 | c4 | c5 |
| d1 | d4 | d5 |
If you're getting this data from a database, though, you can probably let the database handle the slicing of each row... either by using selectall_arrayref and its Slice option, or by just listing the required columns in the query.
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Sending data for LOOP in HTML::Template
by Steny (Sexton) on May 30, 2004 at 20:30 UTC | |
by neniro (Priest) on May 30, 2004 at 21:00 UTC |