in reply to Re^2: creating HTML table
in thread creating HTML table
#!/usr/bin/perl -w use strict; use diagnostics; use HTML::Template; open( OUT, ">fruit.html" ) or die "cant open out $!"; my $html = do{local $/;<DATA>}; my $tpl = HTML::Template->new( scalarref => \$html, loop_context_vars => 1, filter => \&cstmrow_filter ); my @rows = ( "Apple", "Orange", "Mango", "Kiwi" ); my @loop_data = (); # initialize an array to hold my loop while (@rows) { my %row_data; # a hash for my data list $row_data{FILES} = shift @rows; push( @loop_data, \%row_data ); } $tpl->param( rows => \@loop_data ); print OUT $tpl->output; sub cstmrow_filter { my $text_ref = shift; $$text_ref =~ s/<CSTM_ROW\s+EVEN=(.+)\s+ODD=(.*)\s*> /<TMPL_IF NAME=__odd__> <tr class="$1"> <TMPL_ELSE> <tr class="$2"> <\/TMPL_IF> /gx; } __DATA__ <head> <style type="text/css"> .odd { background-color: #d3d3d3 } .even { background-color: #90ee90 } </style> </head> <body> <p> <table class="center"> <TMPL_LOOP NAME=rows> <CSTM_ROW EVEN=even ODD=odd> <td> <TMPL_VAR NAME=FILES></td> </tr> </TMPL_LOOP> </table> </p> </body> </html>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: creating HTML table
by Cody Pendant (Prior) on Jul 16, 2007 at 10:29 UTC | |
|
Re^4: creating HTML table
by holli (Abbot) on Jul 16, 2007 at 10:39 UTC | |
|
Re^4: creating HTML table
by Cody Pendant (Prior) on Jul 16, 2007 at 12:33 UTC | |
by GertMT (Hermit) on Jul 16, 2007 at 12:58 UTC |