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>

In reply to HTML::Template create table by GertMT

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.