in reply to search and variable interpolation in templates
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:s/\[([^]]+)\]/<TMPL_VAR NAME=$1>/g;
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!my $t=HTML::Template->new(filename=>'file.html'); $t->param(var=>'AgentM\'s Print-o-Matic'); $CGIquery->print $t->output;
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)!
|
|---|