Re: [htmltmpl] HTML Template - fatal error in loop output
Brought to you by:
samtregar
From: Brad B. <bm...@ma...> - 2005-11-11 19:34:14
|
On 11/10/05, Senthil Nathan <rs...@gm...> wrote: > Hi Roger, > > Thanks. That works now. > > This is how I did it, > foreach $instance(@diagnosis) > { > my %row =3D ( > line =3D> $instance > ); > push(@diag, \%row); > } > $template->param(dign_loop =3D> \@diag); > > So, Can't we directly pass an array to the template????? Well, you do pass an array (ref) directly to the template. But, as you have shown above, it must be an array of hashes. You could shorten your code a little: $template->param( dign_loop =3D> [ map { line =3D> $_ }, @diagnosis ] ); The problem with accepting an array of strings is you must somehow indicate in the template where each string should be placed. Your expectation seemed to be to use the name of the array as the placeholder. There are a number of reasons why that approach is not a good one (IMO), but the simplest argument is that the method doesn't know the name of the array. ... long story short, make each array element a hash, use the hash key(s) as your placeholder(s), and you're set. Regards, Brad |