in reply to Re: using HTML::Template to update a file
in thread using HTML::Template to update a file

Thanks Ovid for your time spent clarifying this for me.

I understand the faults with my original script, and have corrected them accordingly.

Another problem I had which you could not have known about is that I defined $indx too early in the script since its path is dependent upon $Number

I now have the following script:
use strict; use CGI ':standard'; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use HTML::Template; my $db="/path/edit/data.txt"; print header(); 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) { my $indx = "/path/pages/$Number/index.html"; 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>"; } } close DB; print end_html();
This seems to function well and all my files are now brought up to date when I make a change to the template file.

Thanks once again for your help