Ah, that makes sense, because you want the HTML output to be in the right order. The tricky thing is that the outer hash and each of the inner hashes must be tied to Tie::IxHash... I'm trying to imagine the code for that, and it's not coming out very pretty. :)

So, I'll propose an array of arrays solution instead.

my @tmpl_array = ( 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 $i = 0; $i < $#tmpl_array; $i+=2) { my($loop, $aref) = @tmpl_array[$i, $i+1]; my @vars; for (my $j = 0; $j < $#{$aref}; $j+=2) { my($name, $url) = @{$aref}[$j, $j+1]; push @vars, { name => $name, url => $url }; } $template->param($loop, [ @vars ]); }
We're sort of simulating the ordered hashes, by having paired elements in each of the arrays. This works because we don't actually need any hash key lookups!

Update: This code would be used with the same updated template as the hash of hashes suggestion in my earlier reply.


In reply to Re: Re: (2) Got those HTML::Template and subroutine blues (tie hash o' hashes?) 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.