and the template file would look like this:# parses HTML files as templates ################################################# sub MakeHTML { my ($file,%HTML) = @_; my ($line,$tag,$html); # open HTML file open(READ,$file) || return(0); foreach $line (<READ>) { foreach $tag (keys %HTML) { # substitute tags $line =~ s/\[$tag\]/$HTML{$tag}/gi; } # gather parsed HTML $html .= $line; } close(READ); return($html); } # assign things like $STUFF{'myname'} = 'John Burbridge'; $STUFF{'myage'} = 26; # then print it my $html = MakeHTML('/path/to/template.htm',$STUFF) or Errors('couldnt parse the template'); print "Content-type: text/html\n\n"; print $html;
Sure it looks pretty simple and handy at 1st glance, but beleive me: ITS A BAD HABIT. I had to learn this the hard way...<html><body> My name is [myname] and I am [myage] years old. </body></html>
In reply to RE: RE: Design vs. Code vs. Maintenance
by BBQ
in thread Design vs. Code vs. Maintenance
by BBQ
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |