QUOTE
Hate having to place all the print statements in your program and having to escape all those quotes?

Would you like to give the ability for people who don't know how to program in perl to customize the output of your cgis?

Templates are the answer. Here's how it works. Take any html file and anywhere you place in(variable), it gets replaced with $in{'variable'}. For example, if you have $in{'name'} = 'bob' and an html file that has:
Name: in(name)

The output would look like:
Name: shiv


QUOTE
Usage (Step 1):

Use this code to call the subroutine. Replace [page] with either a relative or full path to the html template. Example: &PageOut("t_index.htm"); where 't_index.htm' is your template file. Any line that has in(variable) will be replaced with $in{'variable'}


CODE
&PageOut("[page]");



Code (Step 2):

Add the following code somewhere within your script.


CODE
sub PageOut{
local($file) = @_;
open(OUT,"$file")||print "$!: $file<br>";
while(<OUT>){
$_ =~ s/in\((\w+)\)/$in{$1}/g;
print;
}
close OUT;
}




njoy!

shiv

 

 

 


Reply