[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] How To Scripts



Ken,

> Problem: One of the major tasks of a CGI script is to provide some kind
> of dynamic HTML.
> I would like to use HTML created by a graphic artist, but I would like
> to alter some of the contents dynamically. This requires me to parse the
> HTML file created by an artist and insert my own information.

I haven't been following this thread closely, but I would recommend thinking very 
carefully before building a site around "solution" scripts you've found in some 
book. The hope is that the cookbook approach will save you time (especially if 
you're not familiar with Perl), but in the end it's likely you'll spend more time 
trying to figure out and debug someone else's code. (I've been down that road.)

If what you're after is using perl to build dynamic pages, you might consider the 
widely used Text::Template module available from CPAN. (You should be able to use 
Chris Nandor's Mac CPAN stuff to install it on the MacOS.)

This is a general module for using templates-- it parses them, and substitues 
variables with the values they should take on. What's nice about this module (and 
why I suspect it's so widely used) is that you can also embed Perl within the 
template itself, and that code is also executed when the template is parsed.

As one possible implementation (and there are many), your entire website could be 
built around one script (index.cgi) that determine which page is being requested 
(index.cgi?page=contacts.html) and then used Text::Template to parse the template 
(contacts.html) and print it to the browser. The contacts.html template could 
contain straight HTML (as designed by your designer) with substitued variables 
{$TITLE}, {$DATE} etc., or even include Perl code.

Here's a sample use of Text::Template from one of our sites. This code defines a 
variable that will be found in the template, $result, and then creates the 
template object, and prints it out:

		$result = "<B>A Error Occurred.</B> Our server seems to 
				think that the email address you entered is 
				not valid. Could you please check the address, 
				and try again. Thank You.")."<BR>";
	
		$temp = new Text::Template(
				TYPE => 'FILE',
				DELIMITERS => ['{', '}'],
				SOURCE => $TEMPLATES_PATH.'mailinglist-form.html');	

		$temp->fill_in();

As you can see, it's very easy to use. More information about Text::Template 
should be available at:

	http://www.plover.com/~mjd/perl/Template/

Hope this helps,

	-- Matt

Matt Henderson  | matt@makalumedia.com | http://www.makalumedia.com/




===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org