GUFE Walkthrough: Part 5
November 8, 1999
Speaking of &createPage ...
sub createPage {
#insert the table into the template page
#the HTML template page must contain the comment
#<!--FRONTEND--> where you wish GUFE's output to appear
my ($tableHTML)=@_;
#full filesystem path to template HTML page
my $templatePage="gufe.html";
my $finalPage="";
open (INFILE,"$templatePage");
my @template=<INFILE>;
close (INFILE);
$finalPage=join('',@template);
$finalPage=~s/<!--FRONTEND-->/$tableHTML/;
return $finalPage
} #end createPage
Unlike the varied responsibilities of &resultTable,
the above subroutine has one straightforward goal: insert
the HTML from &resultTable into the HTML
template page. We open up the template file, specified
in $templatePage, join the file into one long line,
and search-and-replace the known comment tag with the
entire HTML chunk that GUFE has generated. This subroutine
returns its result -- the entire HTML page -- to the
calling statement, which was print(), causing it to
be sent to the browser. Sweet peas.
Conclusion
We've spent a lot of time this month looking at segments
of code and narrating segments of code. But the real
core of this article is the code itself. If you want to
implement, modify, or better yet, understand GUFE's
application to your own web-based database you should
spend time reading, tinkering, reading, and tinkering
some more with the
full unmodified GUFE script.
In the next installment of this Perl You Need to Know
mini-series, Dabbling in Live Databases, we'll extend
GUFE further -- and our work with databases -- to
inserting new data into an existing database. Can't you feel
the tingle?
Resources
GUFE Walkthrough: Part 4
The Perl You Need to Know
|