[Templates] tied hash - puzzlement

hugh@tao.ca hugh@tao.ca
Sun, 12 Jan 2003 19:23:39 -0500


allan <lambretta@inet.uni2.dk> writes:

> just wondering ...
>  
> i have got a tied hash that i know is sorted/inserted correctly before
> i send it to TT.
>
> if using syntax 1 below TT will produce the same result as when i loop
> directly in perl. 
> however syntax 2 will always be sorted by the key in the hash. is this
> a feature ?

the Template::Iterator object sorts hashes by keys.  this is probably
what is causing unexpected behaviour with your presorted hash. perhaps
the hash should be explicitly sorted when passed to the Iterator.

something like:

          [% FOREACH item = hash.key_sort;
          	item.key; ": "; item.value;
             END %]

A 'value_sort' would also be handy for some types of labled data.
Just a thought.

    hugh.

--