Juerd complained about unreadable templating code here Juerd then supplied a snippet that was nice, but non-nestable and non-assignable. Here is an attempt to maintain the niceness of the original snippet, and also make it reusable and assignable.
=for comment Here we retain Juerd's nice readable curly-brace syntax, and we also allow for reusable code (by assigning to global output string) allow for paramaterized tags (by using array ref with prm_table) allow for multiple-nested tags of any nesting-depth =cut ### INIT ### ---------------------------------------------- use strict; use warnings; ### INIT vars; global output string buffer; params for the parent +table; my $out; my $set_prm_table = [qw(red 1 100%)]; sub prm_table (&@){ my $st = $_[1] || ""; $out .= "<table bgcolor='$st->[0]' border='$st->[1]' width='$s +t->[2]'>"; $_[0]->(); $out .= "</table>"; } sub row (&) { $out .= "\n<tr>"; shift->(); $out .= "</tr>"; } sub cell (&) { $out .= "\n<td>"; shift->(); $out .= "</td>";} ### DISPLAY OUTPUT ### ---------------------------------------------- prm_table { for (1 .. 3){ row { cell {$out .= "foo $_"} } } }$set_prm_table; print $out; print "\n---------------------------\n";

In reply to Readable HTML tables (revisited) by dimar

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.