If the template is very small, probably the most efficient method is to print directly:
print <<OUT;
First line!
This line has a $var in it.
Second line...
Thanks for reading this!
OUT
If your template is large but has only a few insertion points, you can read the file into a string and use index or rindex:
use strict;
use warnings;
my ($handle, $text, $insert);
open($handle, 'template.txt');
read($handle, $text, 10000);
close($handle);
$insert = index($text, '<!-- INSERT -->');
print substr($text, 0, $insert);
print 'My inserted data goes here!';
print substr($text, $insert);
Beyond that, a formal templating system or module is probably best, or you can always use PHP, which is designed for embedding in pages:
Blah blah blah
I'm inserting a variable here: <?php echo $var; ?>
And again here: <?php echo $another; ?>
I still like using PHP for simple things. |