Solved

perl send processing page

Posted on 2002-07-26
2
212 Views
Last Modified: 2010-03-05
I am trying to write a PERL script which does quite a bit
of processing before it displays anything to the browser.
I want to send to the browser a message like "Working on your
query" while the processing is happening.  Does anyone know
of a trick or tip to send HTML code to the browser while
processing is taking place?

I have found some comments on the web,
saying I should do $|=1 to to bypass script buffer,
and I need to bypass web server buffer too.  I am using
apache server 1.3.

Can somebody give me a working example?
Thanks.

0
Comment
Question by:xiaoxiangz
2 Comments
 
LVL 6

Accepted Solution

by:
sstouk earned 140 total points
ID: 7181083
Perhaps you will find my example useful:

#!/usr/local/bin/perl
use CGI qw(:standard);
$|=1;
$cgi = new CGI;
$ACCESS_PATH = &GET_SCRIPT_FULL_PATH . "?p=1;";

print $cgi->header;
print " <html>";
print "<head>";
print "<title>$TAG_WEBTITLE. Version: $VERSION_NUMBER</title>";
print "   <meta http-equiv=\"Content-Type\" content=\"html\"; charset=\"$TAG_CHARSET\">";
print "   <meta name=\"Author\" content=\"Sergy Stouk\">";
print "   <meta name=\"GENERATOR\" content=\"Mozilla/4.74 [en] (Windows NT 5.0; U) [Netscape]\">";
print "</head>";
print "<body>";

print "Please Wait ... processing Your data...";

if (param('p'))
{
# Emulating Processing of Data;    
     for ($i=0;$i<10;$i++)
     {
     sleep(1);
     };
print "Welcome... Your Data is processed...";    
} else {
     print "Please Wait While Directing to a new Page.....";
     sleep(3);
     J_LOCATION($ACCESS_PATH);
     };
print "</body></html>";
exit;

sub J_LOCATION
{
print qq{ <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
         <!--
         window.location.replace("};

print "$_[0]";

print qq{")
         // -->
         </SCRIPT>
         };
};

sub GET_SCRIPT_FULL_PATH
{
my($temp) = undef;
my($LOCAL_ADDR) = undef;
my($SCRIPT_NAME) = undef;
my($SCRIPT_PATH) = undef;
my($SCRIPT_FULL_PATH) = undef;
$LOCAL_ADDR= $ENV{"SERVER_NAME"};
$_= $ENV{"SCRIPT_NAME"};
($SCRIPT_PATH,$SCRIPT_NAME) = /(.*)\/(.*)$/;
$SCRIPT_FULL_PATH = "http://$LOCAL_ADDR"."$SCRIPT_PATH"."/"."$SCRIPT_NAME";
return $SCRIPT_FULL_PATH;
};

0
 

Author Comment

by:xiaoxiangz
ID: 7181216
It works.

#!/usr/local/bin/perl
use CGI qw(:standard);
$|=1;
$cgi = new CGI;
 
print $cgi->header;
print " <html>";
print "<head>";
##Strange, If I remove any meta statement, it doesnot work
print "   <meta http-equiv=\"Content-Type\" content=\"html\"; charset=\"$TAG_CHARSET\">";                                        
print "   <meta name=\"Author\" content=\"Shane Zhang\">";
print "   <meta name=\"GENERATOR\" content=\"Mozilla/4.74 [en] (Windows NT 5.0;
U) [Netscape]\">";
print "</head>";
print "<body>";
 
print "Please Wait ... processing Your data...<br>";
 
# Emulating Processing of Data;    
    for ($i=0;$i<10;$i++)
    {
    sleep(1);
    print "step " . $i. "<br>";
    };  
print "Welcome... Your Data is processed...";
print "</body></html>";
exit;
 
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question