Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

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

I'm trying to learn more and more about how I can use HTML::Template to optimize what I've previously done "statically" with CGI.pm.

Here's a place where I'm currently snagged:

my $snapdir = "/some/path/to/snapshots"; my @iso = ('ca', 'zh_CN', 'cs', 'da', 'en', 'fo', 'fr', 'de', 'it', 'ja', 'no', 'pl', 'ru', 'es', 'th', 'tr'); my @lang = ('Catalan', 'Chinese', 'Czech', 'Danish', 'English', 'Faroese', 'French', 'German', 'Italian', 'Japanese', 'Norwegian', 'Polish', 'Russian', 'Spanish', 'Thai', 'Turk +ish'); my @languages; push @languages, { name => $lang[$_], iso => $iso[$_], file => "viewer_$iso[$_].prc", }, foreach (0..$#iso); print '<table border="1">'; print '<th>Language</th>'; print '<th>Last updated</th>'; foreach (0..$#iso) { my $string = shift; my $viewer = { name => $lang[$_], iso => $iso[$_]}; my $ppi = { name => $lang[$_], iso => $iso[$_]}; $viewer->{file} = "$root/viewer_$iso[$_].prc"; $ppi->{file} = "$root/ppi_$iso[$_].prc"; next unless stat($viewer->{file}); $viewer->{size} = (CORE::stat($viewer->{file}))[7]; $ppi->{size} = (CORE::stat($ppi->{file}))[7]; $viewer->{time} = (CORE::stat($viewer->{file}))[9]; $ppi->{time} = (CORE::stat($ppi->{file}))[9]; $languages[$_] = $viewer; my $name = sprintf("%-12s", $viewer->{'name'}); my $filedate = strftime "%D %r", localtime $viewer->{'time' +}; my $filesize = insert_commas($viewer->{'size'}); my $ppisize = insert_commas($ppi->{size}); print "<tr>"; print "<td align=\"right\">" . $cgi->a({-href=>substr("$snapdir/$viewer->{'file'}", 3 +5), -title=>"$filesize bytes"}, "$name") . "(" . $cgi->a({-href=>substr("$snapdir/$ppi->{'file'}" +, 34), -title=>"$ppisize bytes"}, "ppi") . ")" . "</td>"; print "<td>$filedate</td>"; print "</tr>"; } print "</table>"; print $cgi->end_div();

What is the easiest way to convert this construct into something that HTML::Template, via TMPL_LOOP, can grok?


In reply to Converting "static" CGI.pm code into HTML::Template loops by hacker

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, 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
  • 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.
  • 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 studying the Monastery: (6)
    As of 2020-08-07 14:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Which rocket would you take to Mars?










      Results (45 votes). Check out past polls.

      Notices?