Hi, I use the following snippet to create a file using HTML::Template:
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;
This works no problem.

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:

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();
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).

Can anyone come to my rescue?


In reply to using HTML::Template to update a file by jonnyfolk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.