[Templates] How to create Tied hashes?

Subbu Meiyappan asicjunkie@gmail.com
Wed, 21 Jun 2006 00:04:07 -0700


------=_Part_4838_25696654.1150873447670
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Probably an asked question: How do I create a tied hash so that when I
retrieve the keys, I get it back in the order I inserted inside of TT2?.
Example:

[% hash = {
        one = 1,
        two = 2,
        three = 3
       };
%]

[% FOREACH key IN hash.list('keys');
     "$key\n";
     END;
%]

I'd like it to print
one
two
three

every time, deterministically. In regular perl, we use Tied hashes to
achieve this effect. How do I do this TT? Obviously, I don't want to use the
sort method, since my keys are random.

Thanks
Subbu

------=_Part_4838_25696654.1150873447670
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

<div>Probably an asked question: How do I create a tied hash so that when I retrieve the keys, I get it back in the order I inserted inside of TT2?. Example:</div>
<div>&nbsp;</div>
<div>[% hash = {</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; one = 1,</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; two = 2,</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; three = 3</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };</div>
<div>%]</div>
<div>&nbsp;</div>
<div>[% FOREACH key IN hash.list('keys');</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; &quot;$key\n&quot;;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; END;</div>
<div>%]</div>
<div>&nbsp;</div>
<div>I'd like it to print</div>
<div>one</div>
<div>two</div>
<div>three</div>
<div>&nbsp;</div>
<div>every time, deterministically. In regular perl, we use Tied hashes to achieve this effect. How do I do this TT? Obviously, I don't want to use the sort method, since my keys are random.</div>
<div>&nbsp;</div>
<div>Thanks</div>
<div>Subbu</div>

------=_Part_4838_25696654.1150873447670--