Re[3]: A perl program to translate HTML to Perl?

Christopher Taranto (christopher@tokpela.com)
Thu, 16 Apr 1998 13:11:51 -0700


NOTE: I had originally not cc'd the list (by accident), so here's my reply
to Richard in case this helps other people too.

Hi Richard,

OK, now I understand more of what you are trying to do.  I am not familiar
with CyberStudio but I have had a similar issue with my company.  My
partner designs the HTML and places "variables" into the HTML that
represent HTML chunks (such things as common headers and footers).  He
actually designs all of the pages and takes out the repetative stuff and
puts them into a central text file that we call a "sitewrapper" database.
We were going to do this on the fly but we found that it is much easier to
actually parse our files (which start as .template files) and update the
pages into HTML since this stuff is semi-static.  Furthermore, we actually
do this on our local/test site so he can view the html pages and make
changes to the sitewrapper database and rerun the sitewrapper parser script.

As far as dynamic content, I also created a parser object (which just so
happens to be the base of the sitewrapper script) that runs in my CGI
scripts; the parser object takes a hash and the page content and replaces
all instances of the variables in the hash and returns the page.  This
works well with getting the %FORM information and (if necessary) adding
other things to %FORM (such as other stuff that would be dynamic).

For example:

Let's say that I have posted a form with firstname and lastname in the form
field.  Now I looked up that person's information in a database and
retrieved a record.  I would format the record into HTML and add to an item
to FORM called database_record.  The return page would have a variable
called $database_record and would be parsed and filled-in.  So now the code
would be something like this:

.... I've already invoked READPARSE (or whatever)

my $firstname             = $FORM{'firstname'};
my $lastname              = $FORM{'lastname'};

my $database_record       = ..do my lookup stuff here and do any <TABLE>
formatting etc...

$FORM{'database_record'}  = $database_record;

my $return_page           = (load the HTML file from disk);

my $parser                = TPARSER->new();

# this parses all of the variables in %FORM
############################################

$parser->prepare('parser_variables' => \%FORM,
                 'return_page'      => $return_page);

# this does *not* use eval!!!
############################################

$return_page              = $parser->parse();

print "Content-type: text/html\r\n\r\n"
print $return_page;

The return page is really a template.  I'm not sure if this pertains to
your situation but if it does let me know and maybe we can tailor something
for you.

Christohper Taranto

At 02:26 PM 4/16/98 +0900, you wrote:
>Hi,
>
>At 08:33 PM 4/15/98 -0700, you wrote:
>>Richard,
>>
>>>has anyone built a Perl program that can take HTML and convert it to a Perl
>>>program that uses CGI.pm to produce the same HTML?
>>
>>I'm not quite sure what you are trying to accomplish here?   Are you trying
>>to return an HTML page from a CGI POST or GET?
>
>Umm, no. Know how to do that. Simple Perl program.
>
>>>We are building pages using CyberStudio, but many of these pages need to be
>>>translated to Perl as CGI scripts. Hand translating them is a pain.
>>
>>This makes even less sense to me since it would not work to make an HTML
>>page into a cgi script.
>
>Well, it is a site development issue. Cyberstudio makes it very easy to lay
>out pages and get a good look and feel, esp if you have a Web-aware graphic
>designer doing the work. However, if these pages have to have dynamic
>content added, they need to be re-layed out as CGI scripts. 
>
>Much more productive if we can do 90% of the work automagically, and then
>only have to hack in a few calls to a database via DBI::DBD to get the data
>that needs to go on the page from a database.
>
>
>
>Regards
>-------
>Richard Sharpe, sharpe@ns.aus.com, NIC-Handle:RJS96
>NS Computer Software and Services P/L, 
>Ph: +61-8-8281-0063, FAX: +61-8-8250-2080, 
>Linux, AIX, Digital UNIX, ULTRIX, SunOS, Samba, Apache, NetScape, ICSS,
>Perl, C, C++ ...
>
>