Is there any specific reason you need to squeeze everything into a single hash key/template variable?  Why not create a proper nested data structure, which you can then access something like this in the template

[% TimeData.RemainingDays.$status.$percent %]

To elaborate, here's some sample code:

#!/usr/bin/perl -w use strict; use Template; my $vars; $vars->{Stati} = [ qw(NEW ASSIGNED) ]; $vars->{UtilRatioPercent} = [ qw(25 50 75) ]; for (1..3) { my $item; for my $status (@{$vars->{Stati}}) { for my $percent (@{$vars->{UtilRatioPercent}}) { $item->{RemainingDays}{$status}{$percent} = int(rand 42); } } push @{ $vars->{ReturnValues} }, $item; } #use Data::Dumper; print Dumper $vars; exit; # debug my $templ = q{ [% FOREACH status IN Stati %] [% FOREACH percent IN UtilRatioPercent %] [% FOREACH TimeData IN ReturnValues %] Remaining ([% status %]-[% percent %]): [% TimeData.RemainingDay +s.$status.$percent %] days [% END %] [% END %] [% END %] }; my $tt = Template->new(); $tt->process(\$templ, $vars) or die $tt->error();

Output (superfluous whitespace removed):

Remaining (NEW-25): 0 days Remaining (NEW-25): 29 days Remaining (NEW-25): 11 days Remaining (NEW-50): 29 days Remaining (NEW-50): 4 days Remaining (NEW-50): 14 days Remaining (NEW-75): 23 days Remaining (NEW-75): 23 days Remaining (NEW-75): 27 days Remaining (ASSIGNED-25): 3 days Remaining (ASSIGNED-25): 5 days Remaining (ASSIGNED-25): 13 days Remaining (ASSIGNED-50): 3 days Remaining (ASSIGNED-50): 23 days Remaining (ASSIGNED-50): 3 days Remaining (ASSIGNED-75): 14 days Remaining (ASSIGNED-75): 1 days Remaining (ASSIGNED-75): 37 days

In reply to Re: Perl Template::Toolkit combining variables? by Anonyrnous Monk
in thread Perl Template::Toolkit combining variables? by Frederic_S

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.