Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Greetings atcroft,

One of the things I've noticed about HTML tables is that in some browsers you have to specify blank cells with " " or else something yucky looking gets put into the final display. So the code of my attempt to answer your question inserts blank cell data for whatever remaining cells are in the table.

use strict; my @set_of_stuff = (1,3,4,6,7,8,10,12,13,14,15,19,23); my $items_per_row = 4; my @table_data; for (0 .. scalar @set_of_stuff / $items_per_row) { my @row_data = map {$_={cell_data=>$_ }} splice(@set_of_stuff,0,$ite +ms_per_row); push @row_data, {cell_data=>'&nbsp'} while scalar @row_data < $items +_per_row; push @table_data, { row_data => \@row_data }; }

Also, I really like letting the brilliance of the module handle what data goes where in what type of table. I lean away from mucking around with the template itself (i.e. inserting "break" variables to set the rows) and rather prefer to let the module setup the table via the data. Gryphon's personal rule of HTML::Template: Put as much of the "thinking" into the Perl as possible leaving a simpler template.

use HTML::Template; my $template = q{ <TABLE border=1><TMPL_LOOP name="table_data"> <TR><TMPL_LOOP name="row_data"> <TD><TMPL_VAR name="cell_data"></TD> </TMPL_LOOP></TR> </TMPL_LOOP></TABLE> }; my $template = HTML::Template->new(scalarref => \$template, option => +'value'); $template->param(table_data => \@table_data); print $template->output();

General aside: When I was first playing around with HTML::Template, I was really annoyed with having to deal with all the references required. However, once I got used to it, I've come to realize that the elegance and brilliance of the module is all about putting all the "thinking" in your Perl and only the HTML in the templates. I'm amazed at what the author's done just about every time I use it.

gryphon
code('Perl') || die;


In reply to Re: A question regarding HTML::Template, tables, and loops by gryphon
in thread A question regarding HTML::Template, tables, and loops by atcroft

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (4)
    As of 2014-09-21 16:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (172 votes), past polls