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

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

Dear Monks,
I'm struggling once more with HTML::Template. As an example I provide a tiny csv-file that I use as a database. I currently use Data::Table (...for all kind of shuffling that's not mentioned here...) but the HTML output that comes from the script that is shown below (SelectDataScript) is not really what I want. If I would like to use HTML::Template I understand I need to feed the data into an array of hashes but currently I'm getting nowhere. Guess my template (see below 'template_whthr.tmpl') should work but can't I use the $table object that was generated in some way?
I'm grateful for any clues.
Gert
wheather.csv
Monday,snow Tuesday,rain Wednesday,snow Thursday,snow Friday,sunny Saturday,snow Sunday,rain

SelectDataScript
#!/usr/bin/perl -w use strict; use diagnostics; use HTML::Template; use Data::Table; use DBI; # open( OUT, ">snow.html" ) or die "cant open out $!"; my $dbh = DBI->connect( 'dbi:AnyData(RaiseError=>1):' or die $DBI::err +str ); $dbh->func( 'whthr', 'CSV', 'wheather.csv', { sep_char => ',', # eol => "\015", col_names => 'day,type' }, 'ad_catalog' ); my $table = Data::Table::fromSQL( $dbh, "SELECT day, type FROM whthr WHERE type='snow'" ); print $table->html; # not the preferred formatting print $table->csv; # ? # for my $row (@rows) { # push( @loop_data, {FILES => $row} ); # } # Can I use the object $table for the $template of HTML::Template? # my $template = HTML::Template->new( filename => 'template_whthr.tmpl +' ); # print OUT $template->output;
template_whthr.tmpl
<p> <table class="center"> <TMPL_LOOP NAME=ROWS> <tr> <td> <TMPL_VAR NAME=day></td> <td> <TMPL_VAR NAME=type></td> </tr> </TMPL_LOOP> </table> </p>