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/
-----------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY style="MARGIN-TOP: 2px; FONT: 8pt Tahoma; MARGIN-LEFT: 2px">
<DIV><FONT size=2>Hi</FONT></DIV>
<DIV><FONT size=2>I have a p</FONT><FONT size=2>roblem when returning 
single-element arrays from perl functions. </FONT></DIV>
<DIV><FONT size=2>I am using TT 2.08, Activestate perl 5.6.1, Redhat 
7.3</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>In the following simplified example, a perl function returns 
an array of pointers to hashes</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [% a = 
test_function() %]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [% FOREACH b = 
al %]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name = [% b.name 
%] &lt;br&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [% END 
%]<BR></FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Perl 
function</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub 
test_function{</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 
({name=&gt;"bob"}, 
{name=&gt;"fred"});<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;</DIV>
<DIV>This produces, correctly, the output</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; Name = bob</DIV>
<DIV>&nbsp;&nbsp;&nbsp; Name = fred</DIV>
<DIV>&nbsp;</DIV>
<DIV>However, if the array contains only a single hash pointer( return 
({name=&gt;"bob"}); ) , TT interprets this as a hash, rather than an array 
containing a single element (and FOREACH produces some strange results).</DIV>
<DIV>&nbsp;</DIV>
<DIV>This problem can be fixed by returning an array pointer rather than an 
array (ie return [ {name=&gt;"bob"}, {name=&gt;"fred"} ];)</DIV>
<DIV>but surely if TT can handle being returned an array, it should not fail in 
this one case</DIV>
<DIV>&nbsp;</DIV>
<DIV>Is this a bug, or a feature? =) And is there any way around it apart from 
just always returning a pointer?</DIV>
<DIV>&nbsp;</DIV>
<DIV>Cheers</DIV>
<DIV>Jay Baker<BR></DIV></FONT><FONT size=2></FONT></BODY></HTML>

Reply via email to