Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2024-04-25 11:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found