logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Issues interpreting arrays returned from perl functions: msg#00072

Subject: Issues interpreting arrays returned from perl functions
Hi
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
 
In the following simplified example, a perl function returns an array of 
pointers to hashes
 
        [% a = test_function() %]
        [% FOREACH b = al %]
          Name = [% b.name %] <br>
        [% END %]

        # Perl function
        sub test_function{
          return ({name=>"bob"}, {name=>"fred"});
        }
 
This produces, correctly, the output
 
    Name = bob
    Name = fred
 
However, if the array contains only a single hash pointer( return 
({name=>"bob"}); ) , TT interprets this as a hash, rather than an array 
containing a single element (and FOREACH produces some strange results).
 
This problem can be fixed by returning an array pointer rather than an array 
(ie return [ {name=>"bob"}, {name=>"fred"} ];)
but surely if TT can handle being returned an array, it should not fail in this 
one case
 
Is this a bug, or a feature? =) And is there any way around it apart from just 
always returning a pointer?
 
Cheers
Jay Baker



-----------------------------------------------------------------------
This email contains confidential information. If you have received this
email in error, please delete it immediately, and inform us of the mistake
by return email. Any form of reproduction, or further dissemination of
this email is strictly prohibited.
Also, note that the opinions expressed in this email are those of the 
author and are not necessarily those of the Fonterra Co-operative Group

http://www.fonterra.com/
-----------------------------------------------------------------------

Attachment: TEXT.htm
Description: Text document

<Prev in Thread] Current Thread [Next in Thread>