Home: Perl Programming Help: Intermediate:
Updating a site with new data



adrockjames
stranger

Mar 30, 2000, 7:13 AM


Views: 1940
Updating a site with new data

Hello,

I wrote a cgi script in perl that accesses a database and pulls all info from a particular table that has been updated in the past 24 hours. While I can have this info returned from a form, I want have it on a scheduler to run every night and update an internal (i'm at work) site at a particular <table> in the site.

Not sure how I can populate the new data at a particular point in the html. I'm a bit of a rookie, so let me know if any more specifics are needed! An example would be great!


prakashk
Deleted

Mar 30, 2000, 9:40 AM


Views: 1940
Re: Updating a site with new data

You can use any of the several template-based methods to accomplish this. For example (using the module CGI::FastTemplate), you can create a template file (say, table.tpl) containing your HTML code, except the table:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


<HTML>
...

<TABLE>
$my_table_data
</TABLE>
...
...
</HTML>
</pre><HR></BLOCKQUOTE>

Notice the variable name '$my_table_data' above.

Now in your script, do this:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use CGI::FastTemplate;

my $tpl = new CGI::FastTemplate("/path/to/templates");
$tpl->define(table => "table.tpl");

# get your table data and create HTML table rows out of them
# and save it in the variable $latest_data

$tpl->assign(my_table_data => $latest_data);

$tpl->parse(NEW_HTML => "table");
$tpl->print;
</pre><HR></BLOCKQUOTE>

The above code prints your HTML in the template file replacing the variable $my_table_data with HTML rows of your latest data.

This module is available at CPAN. The URL is
<http://search.cpan.org/search?dist=CGI-FastTemplate>

There are several modules on CPAN for template-based text (HTML or otherwise) generation. If you go to <http://search.cpan.org/search?mode=module&query=Template> you'll see a bunch of such modules.

HTH,
Prakash


adrockjames
stranger

Apr 3, 2000, 9:05 AM


Views: 1940
Re: Updating a site with new data

Thanks a million!! Hoping to find some time at work to implement!