Put the 'my %error_data;' inside the loop.  You're pushing a reference to the same hash over and over again.


On Thu, Apr 8, 2010 at 5:20 PM, Shawn Scott <shawn.d.scott@gmail.com> wrote:
Good Afternoon,
I have been using HTML::Template for some time and have recently run into an starnge issue. I have the following code
my @error = @_; 
  my @error_loop = ();
  my %error_data;
  print header;
  foreach  (@error) {
    $error_data{ERROR_DATA} = $_;
    push(@error_loop, \%error_data);
  my $template = HTML::Template->new(filename => "$html_root/signup_error.html");
  $template->param(ERROR_LOOP => \@error_loop);
  print $template->output;
When I run this code it gives me the correct number of elements, based on the number of errors in the loop @error array. The only issue each one is shown as the last line pushed to the @error_loop. If I change the code to this
foreach  (@error) {
    print p"DEBUG - $_\n";
    $error_data{ERROR_DATA} = $_;
    push(@error_loop, \%error_data);
I get the correct vaules printing out in the debug print line but then the actual template loop variables are wrong.
Any help would be great.


Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
Html-template-users mailing list