Jay Baker wrote:
> I have a problem when returning single-element arrays from perl functions. 
> I am using TT 2.08, Activestate perl 5.6.1, Redhat 7.3

The simple answer is that TT doesn't support naked lists.  You should always
return a reference to a list (if you want your results to be interpreted as
a list), rather than just a list of items.

However, TT does automatically fold a single element into a list of that
one element in certains cases.  But this DWIMery can catch you out if 
you're not careful, so it's best to always return a list reference if you
can.

    sub bad_test_function {
      return ( {name=>"bob"}, {name=>"fred"} );
    }

    sub good_test_function {
      return [ {name=>"bob"}, {name=>"fred"} ];
    }

> However, if the array contains only a single hash pointer
> TT interprets this as a hash, rather than an array containing a 
> single element (and FOREACH produces some strange results).

Yes, if you return a hash array then TT will treat it as a hash array.
If you want to return a list containing a single hash array, then you
should return a list (reference) containing a hash array.

HTH
A


_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to