Home : General : Perl Programming :

General: Perl Programming: Re: [mtorres] how do i make html realtime with CGI?: Edit Log

Here is the list of edits for this post
Re: [mtorres] how do i make html realtime with CGI?
Here's what I do:

Have the html and script part in one subroutine then call another subroutine that displays the html results at the bottom.

Example hitting submit gives you whatever.cgi
--------
{
print <HTML>
Please wait processing order....
</HTML>

perl code to process data (split, join, decode, assign variables - whatever)

&display_results;

}

sub display_results {
print <HTML>
here are your results $field1 $field2 $field3
</HTML>
}
--------------

A "real life" example is taken from the GT dbman script I use is below:

Code:
if ($in{'OrderStatus'} eq "process") {

print qq|
<html>
<head>
<title>$html_title: Record Modified.</title>
|; &script_style_headers; print qq|
<META HTTP-EQUIV = REFRESH CONTENT = "3; URL=$db_script_link_url">
</head>

<body bgcolor="#FFFFFF">
<center>
|; &get_record($in{$db_key}); print qq|

<TABLE HEIGHT="100%"><TD>

<FONT FACE="verdana" SIZE="5" COLOR="#DDDDDD">
Processing order, please wait... </font></td></table>
</center>
</body></html>|;

# strips dd/mm/yyyy down to dd/mm/yy for formatting purposes
$rec{'f03_Est_Closing_Date'} =~ s;\d\d(\d\d)$;$1;;
$rec{'f99_FundDate'} =~ s;\d\d(\d\d)$;$1;;
$rec{'f03_Lock_Expiration'} =~ s;\d\d(\d\d)$;$1;;


## Writes data to text File - sends email/attachment
open(TEXT, ">$in{'LoanNo'}.dta") or die "Nada Can Do \n";
select(TEXT);
print qq|1,"$rec{'LoanNo'}"

ANOTHER 3000 LINES OF CODE GO HERE

The META tag gives the browser 3 seconds to display the message (and allow the script to write out data files) before calling another subroutine of the script via the URL. If the server is running slow (sendmail or something) then the end user sees the please wait message a little longer (couple of seconds).

Last edited by:

Watts: Apr 15, 2004, 9:39 AM

Edit Log: