[htmltmpl] Help: HTML::Template Problem
Brought to you by:
samtregar
From: Chan W. T. <cs...@st...> - 2002-08-12 03:04:07
|
Hi Philip, Thank you very much for help. Your explaination is very clear. Since I am used to program in C++, I am quite confused about the usage of perl's variables and objects, especially their declaration and convention. Would you give me some advice, please? Also, I heard that using HTML::Template we could define a variable and a counter in the template. Could you tell me how to use such features, please? I am using HTML::Template version 2.5 . Thanks a lot. Yours, cwt > Sometime Today, Sam Tregar assembled some asciibets to say: > > > use HTML::Template; > > my $htmltemplate = HTML::Template->new("template.htm"); > > my %myHash; > > don't declare the hash here. > > > my @myRecord = []; > > This should either be: > > my @myRecord = (); > > OR: > > my $myRecord = []; > > read man perldata for the difference. > > > for(int $i=0; $i<3; $i++) > > { > > declare the hash here: > > my %myHash; > > > foreach my $obj($htmltemplate->query(loop=>"record")) > > { > > $myHash{$obj} = "Tom".$i; > > } > > push (@myRecord, %myHash); > > you cannot store hashes in arrays. man perldata for why. > > push @myRecord, \%myHash; > > > } > > $htmltemplate->param(record=>@myRecord); > > again, only use a scalar, so: > > ->param(record=>\@myRecord); > > > Philip > > PS: I had written a more elaborate mail, but it got lost accidentally, > so this one's probably a little short. You can search the archives for > the above, it's been asked before. > > > -- > Counting in octal is just like counting in decimal--if you don't use > your thumbs. > -- Tom Lehrer > > > |