Solved

perl send processing page

Posted on 2002-07-26
2
201 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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