[Templates] Process, Loops and Scalar Reference output

Stuart Johnston saj@thecommune.net
Sun, 22 Oct 2006 16:55:22 -0500


Gavin Henry wrote:
> <quote who="Andy Wardley">
>> Gavin Henry wrote:
>>>     $tt->process( \*DATA, $tt_vars, \$email_output )
>>>       || die $tt->error(), "\n";
>> Hi Gavin,
>>
>> The problem is here.  The template is only available to be read
>> from the DATA handle the first time around the loop.  By the second
>> iteration, the DATA file pointer is already at the EOF and it
>> effectively looks like a zero-length template.
>>
>> Try this instead:
>>
>>      local $/ = undef;        # slurp file in one go
>>
>>      my $tt = Template->new(  # define named template
>>          BLOCKS => {
>>              email => <DATA>,
>>          },
>>      );
>>
>>      $tt->process('email', ...etc...)
> 
> Hmmm. It still does the same thing. After the first loop DATA is emtpy,
> and I get:
> 
> Odd number of elements in anonymous hash at ./rt_client_reports line 40,
> <DATA> chunk 1.
> 
> line 40 being "email => <DATA>," from above.
> 
> Do I need to rewind the filehandle iterator?

Only the $tt->process... line should be inside the loop.