How about something like this?
my %tmpl_hash = ( urlloopA => { 'Home' => '/', 'Icons' => '/icons/', 'Sitedocs' => '/doc/', }, urlloopB => { 'Cisco' => 'http://www.cisco.com/', 'CPAN' => 'http://search.cpan.org/', 'Google' => 'http://www.google.com/', 'Perl Monks' => 'http://www.perlmonks.org/', }, ); for my $loop (keys %tmpl_hash) { my @vars; while (my($name, $url) = each %{$tmpl_hash{$loop}}) { push @vars, { name => $name, url => $url }; } $template->param($loop, [ @vars ]); }
with a corresponding change to your template:
<!-- tmpl_loop name="urlloopA" --> <A HREF="<!-- tmpl_var name="url" -->"> <B><!-- tmpl_var name="name" --></B> </A> &nbsp;&nbsp;&nbsp; <!-- /tmpl_loop --> <P> <!-- tmpl_loop name="urlloopB" --> <A HREF="<!-- tmpl_var name="url" -->"> <!-- tmpl_var name="name" --> </A> <BR> <!-- /tmpl_loop -->
The separate hashes become a hash of hashes and the separate loops become a nested loop.

According to the HTML::Template docs, a TMPL_LOOP has its own scope; reusing the same variable names in different loops should work just fine.


In reply to Re: Got those HTML::Template and subroutine blues by chipmunk
in thread Got those HTML::Template and subroutine blues by ybiC

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.