I'm guessing what you mean is "an array of hash references".  If that is 
the case, you need something like:

my $hash = { 'key' => "one",
              'value' => "two",
            };  #Using 'value' as a hash key is a bit confusing

for ($i=0; $i <=6; $i++) {
     push (@list, $hash);
}


On 11/02/2010 12:40 PM, Doug Poulin wrote:
> I'd like to pass a Template an array of hash values and access each set
> in a loop.
> The following test shows what we'd like to be able to do with Template
> but I'm not sure it can be done
> $html= Template->new() || die $html->error;
> #
> # Here is a hash of values
> #
> %hash = { 'key' => "one",
> 'value' => "two",
> };
> #
> # Here we have an array of hash values. This example has really been
> dumbed down to make it simple
> #
> for ($i=0; $i <=6; $i++) {
> push (@list,%hash);
> }
>
> $vars = { ( List => \...@list,
> ) };
> $html->process("test.tmpl",$vars) || die $html->error;
> -------------------------------------------------------------------------------------------------
> Here is the Template file
> -------------------------------------------------------------------------------------------------
> Size of list is [% List.size %]
> [% FOREACH item IN List -%]
> [%# How do we reference one entry in the array? %]
> key is [% item.key -%]<br>
> value is [% item.value -%]<br>
> [% END -%]
> Also List.size returns 14 as the size and not 7 like I'd expect
>
> ------------------------------------------------------------------------
> <http://www.medi.net/>
>
> Doug Poulin
> Medinet Vancouver
> 604 742-8845 (direct)
> 604 742-8850 (fax)
> www.medi.net <http://www.medi.net>
>
>
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates


_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to