Conclusion
July 12, 1999
Generating live HTML content on-the-fly with Perl and the
CGI module is easy. The challenges arise when you
need that live content to be part of a larger, more complex
web page, rather than simply standing on its own. Generating
Web pages in Perl "from scratch", by printing pure
HTML to the browser is intellectually simple but laborious
and unfeasible for complex pages.
The CGI.pm Perl module provides methods which ease generating
sections HTML code, especially forms. But building
large Web pages even with these methods is still a cumbersome
process. Typically, the live content you wish to
generate only occupies a portion of the page, where the rest
of the design is a static template.
The ideal solution, then, is to create the template for the
page outside of Perl, with an HTML authoring tool
of your choice. By using placeholders such as text or HTML
comment tags inside the template page you can mark spots
where live content will be substituted on-the-fly.
You can then write a Perl script which reads in the HTML
template file, generates the live content, and uses
regular expression substitutions to generate a
"new" page, a combination of the HTML template
with the live content.
Live Example
The Smallville Gazette
Tantalizing Templates: Build-a-Pizza Meets the Smallville Gazette
The Perl You Need to Know
The Perl You Need to Know: Part 5 "Processing and Parsing Web Pages"
|