jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:
This works no problem.open (FILE, "$indx_tem") or die " $indx_tem: $!"; open (FILE1, ">$indx") or die "$indx: $!"; while (<FILE>) { # 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); last;
However I have several of these files and I thought it would be useful to write a script to update all existing files if I make a change to the template.
I came up with the following:
Now my debugging at the end prints out all the $Number in the db so I had thought that it was going to work but alas when I checked the file it was from the old template. (When I added a new file to the database, it was created using the new template so I know that there is no mix-up with the templates).print header(); open (FH, "$db") or die "$db: $!"; while (my $line = <FH>) { ($word,$time,$Number,$Location) = split "\t",$line; if ($Number) { #template open (FILE, "$indx_tem") or die "Can't open $indx_tem: $!"; #file to renew open (FILE1, ">$indx") or die "Can't open $indx: $!"; while (<FILE>) { # 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); last; } close FILE; close FILE1; print "finish$Number<br>"; } } print end_html();
Can anyone come to my rescue?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using HTML::Template to update a file
by Ovid (Cardinal) on Mar 05, 2003 at 22:47 UTC | |
by jonnyfolk (Vicar) on Mar 06, 2003 at 12:33 UTC |