From the directive manual: / When the FOREACH directive is used without specifying a target variable, /
/any iterated values which are hash references will be automatically imported./
/ *[% userlist = [
{ id => 'tom', name => 'Thomas' },
{ id => 'dick', name => 'Richard' },
{ id => 'larry', name => 'Lawrence' },
]
%]*// *[% FOREACH user IN userlist %]*
*[% user.id %]* *[% user.name %]*
*[% END %]*// short form: /
/ *[% FOREACH userlist %]*
*[% id %]* *[% name %]*
*[% END %]*// Note that this particular usage creates a localised variable context to prevent the imported hash keys from overwriting any existing variables. The imported definitions and any other variables defined in such a FOREACH loop will be lost at the end of the loop, when the previous context and variable values are restored. /
/ However, under normal operation, the loop variable remains in scope after the FOREACH loop has ended (caveat: overwriting any variable previously in scope). This is useful as the loop variable is secretly an iterator object (see below) and can be used to analyse the last entry processed by the loop. /
My question is related to the 'under normal operation'. What is the abnormal operation? Can I prevent this from occurring in particular i have something like
[% FOREACH country IN countries %] ... [% END %]
[% country %] <-- where this is different then the country above...
so i want it to function as...
foreach my $country ( @countries )
{
...
}The 'under normal operation' suggests to me that this might be possible but I can't find anything
more on scoping for a loop variable.
Your help greatly appreciated...
begin:vcard fn:Sean T. Allen n:Allen;Sean T. org:USA Herbals, LLC email;internet:[EMAIL PROTECTED] title:Tech Guru tel;work:718-388-5424 x-mozilla-html:FALSE version:2.1 end:vcard
