Advertisement

03.15.2008 at 10:04AM PDT, ID: 23244161
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Writing a 'Please Wait' page with spinning object to browser in perl

Tags: perl, perl, 5.8.5, perl, cgi
I have a cgi script that takes a while to process some information, so I'd like to write a 'Please wait' message to the browser while the script processes. I have a little .gif that spins to show the user we're processing their request. Searched the web and found some ideas, but it is this little spinner that is the issue... none of what I found seems to allow the spinning object to do just that -- spin.

Some sample code that hopefully explains what I'm trying to do...
When I get the spinning object to display -- the code looks like this:
## Main
{
  my $q = new CGI;

  if(my $pid = fork ) { # parent
    print $q->header( -type => "text/html",
    ),
    $q->start_html( -class  => 'parent',
                    -title  => 'Please Wait',
    ),
    $q->start_form( -method => 'get',
                    -name   => 'form1',
    ),
    '<center>',
    $q->p( 'Please wait while we collect requested data' ),
    $q->br x 2,
    "<img id='spinner' class='spinner' name='spinner' src='/images/spinner.gif' alt='' />",
    '</center>',
    $q->end_form,
    $q->end_html;
  }
  elsif(defined($pid)) { # child
    sleep(10);
    print $q->header( -type => "text/html",
    ),
    $q->start_html( -class  => 'child',
                    -title  => 'Child Page',
    ),
    $q->start_form( -method => 'get',
                    -name   => 'form1',
    ),
    '<center>',
    $q->p( 'Print my child -- print.'),
    $q->br x 2,
    '</center>',
    $q->end_form,
    $q->end_html;

    exit 0;
  }
  else { # uh oh
    die "Cannot fork.";
  }

  exit;

}

For actually printing the output from the child to the browser:
## Main
{
  my $q = new CGI;

  if(my $pid = fork ) { # parent
    print $q->header( -type => "text/html",
    ),
    $q->start_html( -class  => 'parent',
                    -title  => 'Please Wait',
    ),
    $q->start_form( -method => 'get',
                    -name   => 'form1',
    ),
    '<center>',
    $q->p( 'Please wait while we collect requested data' ),
    $q->br x 2,
    "<img id='spinner' class='spinner' name='spinner' src='/images/spinner.gif' alt='' />",
    '</center>',
    $q->end_form,
    $q->end_html;
    waitpid($pid,0);
  }
  elsif(defined($pid)) { # child
    sleep(10);
    print $q->header( -type => "text/html",
    ),
    $q->start_html( -class  => 'child',
                    -title  => 'Child Page',
    ),
    $q->start_form( -method => 'get',
                    -name   => 'form1',
    ),
    '<center>',
    $q->p( 'Print my child -- print.'),
    $q->br x 2,
    '</center>',
    $q->end_form,
    $q->end_html;

    exit 0;
  }
  else { # uh oh
    die "Cannot fork.";
  }

  exit;

}


So sample #1 above will write my 'Please wait' message complete with an actively spinning object, but I never get the child's output written to the browser; and sample #2 above will write the output from the child, but I get no neat spinning object before the child's output. I know the problem lies somewhere in the realm of not being able to rewrite to the browser (meaning I have to redirect or submit somehow), but I'm not sure exactly how to get where I need to go. Forking seemed to be the a solution, but I'm obviously missing something here.

Any help would be appreciated.

perl: 5.8.5
CGI: 3.29
OS: Linux <hostname> 2.6.9-55.EL #1 Fri Apr 20 16:35:59 EDT 2007 i686 athlon i386 GNU/Linux
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: jhill03
Solution Provided By: hielo
Participating Experts: 2
Solution Grade: A
Views: 55
Translate:
Loading Advertisement...
03.15.2008 at 10:16AM PDT, ID: 21133450

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.15.2008 at 10:24AM PDT, ID: 21133492

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.15.2008 at 12:06PM PDT, ID: 21133854

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.15.2008 at 12:55PM PDT, ID: 21134024

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.15.2008 at 01:22PM PDT, ID: 21134114

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.15.2008 at 06:13PM PDT, ID: 21135178

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.15.2008 at 07:06PM PDT, ID: 21135319

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.15.2008 at 07:44PM PDT, ID: 21135404

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.16.2008 at 10:41AM PDT, ID: 21137678

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628