http://www.perlmonks.org?node_id=296847


in reply to Web app frameworks - I am totally confused!

One technique I often used is a simple HTML template with data tags wrapped inside %% quotes. Simple and effective.
#!/usr/bin/perl -w use strict; use CGI; # Initialize CGI variable my $q = new CGI; # Load HTML my $html; { local $/; $html = <DATA>; } # Format HTML using data callbacks $html =~ s/%%(\w+)%%/&FormatHTML($1)/ge; # Display the HTML print $q->header, $html; exit(0); sub FormatHTML() { my $tag = shift; if ($tag eq "TITLE") { return &FormatTitle(); } elsif ($tag eq "TOC") { return &FormatToc(); } elsif ($tag eq "BODY") { return &FormatBody(); } } sub FormatTitle() { return "HTML Sample"; } sub FormatToc() { return "<b>Table of Contents</b><br>"; } sub FormatBody() { return "<i>Sample text</i>"; } __DATA__ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>%%TITLE%%</title> </head> <body> %%TOC%% %%BODY%% </body> </html>