Re: HTML::Template Loop Issue

Sam Tregar <[email protected]> Thu, 8 Apr 2010 17:53:16 -0400
Newsgroups gmane.comp.lang.perl.modules.html-template
Message-ID <[email protected]>
--===============8240730436088681118==
Content-Type: multipart/alternative; boundary=000e0cd35574c1c8680483c0b48b

--000e0cd35574c1c8680483c0b48b
Content-Type: text/plain; charset=ISO-8859-1

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

-sam

On Thu, Apr 8, 2010 at 5:20 PM, Shawn Scott <[email protected]> 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.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Html-template-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/html-template-users
>
>

--000e0cd35574c1c8680483c0b48b
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Put the &#39;my %error_data;&#39; inside the loop. =A0You&#39;re pushing a =
reference to the same hash over and over again.<div><br></div><div>-sam<br>=
<br><div class=3D"gmail_quote">On Thu, Apr 8, 2010 at 5:20 PM, Shawn Scott =
<span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]">shawn.d.sc=
[email protected]</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex;"><div>Good Afternoon,</div>
<div>=A0</div>
<div>I have been using HTML::Template for some time and have recently run i=
nto an starnge issue. I have the following code</div>
<div>=A0</div>
<div>my @error =3D @_;=A0 <br>=A0=A0my @error_loop =3D ();<br>=A0=A0my %err=
or_data;<br>=A0=A0print header;<br>=A0=A0foreach=A0 (@error) {<br>=A0=A0=A0=
=A0$error_data{ERROR_DATA} =3D $_;<br>=A0=A0=A0=A0push(@error_loop, \%error=
_data);<br>=A0=A0}<br>=A0=A0my $template =3D HTML::Template-&gt;new(filenam=
e =3D&gt; &quot;$html_root/signup_error.html&quot;);<br>

=A0=A0$template-&gt;param(ERROR_LOOP =3D&gt; \@error_loop);<br>=A0=A0print =
$template-&gt;output;</div>
<div>=A0</div>
<div>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 t=
o this</div>


<div>=A0</div>
<div>foreach=A0 (@error) {</div>
<div>=A0=A0=A0 print p&quot;DEBUG - $_\n&quot;;<br>=A0=A0=A0=A0$error_data{=
ERROR_DATA} =3D $_;<br>=A0=A0=A0=A0push(@error_loop, \%error_data);<br>=A0=
=A0}<br></div>
<div>I get the correct vaules printing out in the debug print line but then=
 the actual template loop variables are wrong.</div>
<div>=A0</div>
<div>Any help would be great.</div>
<div>=A0</div>
<div><br clear=3D"all"><br><br>=A0</div>
<br>-----------------------------------------------------------------------=
-------<br>
Download Intel&amp;#174; Parallel Studio Eval<br>
Try the new software tools for yourself. Speed compiling, find bugs<br>
proactively, and fine-tune applications for parallel performance.<br>
See why Intel Parallel Studio got high marks during beta.<br>
<a href=3D"http://p.sf.net/sfu/intel-sw-dev" target=3D"_blank">http://p.sf.=
net/sfu/intel-sw-dev</a><br>_______________________________________________=
<br>
Html-template-users mailing list<br>
<a href=3D"mailto:[email protected]">Html-template-=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/html-template-users=
" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/html-templ=
ate-users</a><br>
<br></blockquote></div><br></div>

--000e0cd35574c1c8680483c0b48b--


--===============8240730436088681118==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
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.
http://p.sf.net/sfu/intel-sw-dev
--===============8240730436088681118==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Html-template-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/html-template-users

--===============8240730436088681118==--