I'm not sure exactly what you're asking, but I noticed some issues with your code, so I thought I would point them out and hopefully they'll help.
Your first code snippet is incorrect. You open your first filehandle and iterate over it, but you don't actually use it and then you last out of it to skip the useless iteration. The code is equivalent to this cleaner (and untested) version:
open NEW_TEMPLATE, "> $indx" or die "Cannot open ($indx) for writing: +$!"; # open the HTML template my $template = HTML::Template->new(filename => $indx_tem); # fill in some parameters in the template $template->param(Location => $Location); $template->param(Number => $Number); $template->param(word => $word); # print the template to file $template->output(print_to => *NEW_TEMPLATE);
Your second code snippet then reduces to something like the following:
open DB, "< $db" or die "Cannot open ($db) for reading: $!"; while (my $line = <DB>) { chomp $line; my ($word,$time,$Number,$Location) = split "\t",$line; if ($Number) { open FILE1, "> $indx" or die "Can't open $indx: $!"; # open the HTML template my $template = HTML::Template->new(filename => $indx_tem); # fill in some parameters in the template $template->param(Location => $Location); $template->param(Number => $Number); $template->param(word => $word); # print the template to file $template->output(print_to => *FILE1); close FILE1; print "finish$Number<br>"; } else { # do you need debugging if you don't use $Number? } } close DB;
Also, it's worth pointing out that iterating over the lines in the "DB" is probably not what you want as your template will only be updated with the last line of data.
Cheers,
Ovid
New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)
In reply to Re: using HTML::Template to update a file
by Ovid
in thread using HTML::Template to update a file
by jonnyfolk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |