Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Tantalizing Templates: Build-a-Pizza Meets the Smallville Gazette

July 12, 1999

At its core, last month's Build-a-Pizza script took input from form fields and constructed an on-the-fly web page. Rather than output its HTML directly to the browser, though, we could redirect the Build-a-Pizza script to generate its HTML to a scalar variable, say, $pizzaHTML. Using the search-and-replace template technique we've already seen, then, it is a small leap to insert the Build-a-Pizza content inside the Smallville Gazette.

Integrating Build-a-Pizza into smallville.cgi results in one somewhat long script which we can only explain in pieces, but you can view the whole script here.

To begin with, we pasted the Build-a-Pizza Perl script at the end of the smallville.cgi script seen earlier. Three changes were then made to the pizza script so that it could integrate into the Smallville script:

  1. Instead of print output, all output strings were assigned to the variable $pizzaHTML. For example,
    print $theform;
    became
    $pizzaHTML.=$theform;
    This way, the HTML output generated by the pizza script builds onto the variable $pizzaHTML rather than being sent directly to the browser.

  2. We removed calls to $cgiobject->header from the pizza script because an HTML header is already generated at the top of the Smallville script.

  3. The main routine of the pizza script which calls the various pizza subroutines was placed into a subroutine of its own, named &build_a_pizza. This simply lets us execute the pizza script with a subroutine call, thus triggering all the code which builds content into $pizzaHTML.

Recalling the first incarnation of smallville.cgi, just after we search-and-replace on the live date and before we output the final page, a few simple lines trigger the Build-a-Pizza substitution:

#generate pizza form
&build_a_pizza;

#search-and-replace on pizza form
$resultPage=~s/INSERT PIZZA HERE/$pizzaHTML/g;

The new smallville.cgi, then, features both the live date and Build-a-Pizza integrated into the Smallville Gazette template based on our relatively simple search-and-replace technique.

Tantalizing Templates: Live Date
The Perl You Need to Know
Conclusion


Up to => Home / Authoring / Languages / Perl / PerlfortheWeb




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers