Legacy code, eh? You do realize that you could prep these files for use with the all-powerful HTML::Template (as you rightfully mention) using a simple regex, right?
s/\[([^]]+)\]/<TMPL_VAR NAME=$1>/g;
Then, in your code, nuke all of the opening, reading, parsing, and closing and replace it with three lines of kiss-HTML::Template's-feet code:
my $t=HTML::Template->new(filename=>'file.html'); $t->param(var=>'AgentM\'s Print-o-Matic'); $CGIquery->print $t->output;
I can only strongly recommend that you do so. As it is, your regex will return strange-looking HTML or invalid HTML altogether if some HTML guy forgets a bracket. HTML::Template catches this. HTML::Template also provides a handy looping mechanism useful for generating tables and forms. In short, you're right, you should've used HTML::Template. But you have the chance now- so take it!

Here's another tip: If you encapsulated your parser (the HTML::Template clone) in the first place in a package, you should easily be able to use your existing code to construct a wrapper class around HTML::Template so that you don't have to change ANY code (just throw in a use HTMLTemplateWrapper; at the start)!

AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

In reply to Re: search and variable interpolation in templates by AgentM
in thread search and variable interpolation in templates by ColonelPanic

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.