in reply to Wait ... Loading ... message in Perl/CGI

The simplest way to go about this (assuming you're sending out HTML) is to send out the "wait..." message in a div or some other structure containing an id attribute, and then when the final output is ready, send out a javascript snippet to remove or make invisible the wait... message. Or just use CSS that places the result right over the message.

This may need some tweaking with buffering, but it works. If the wait time is very long, you will still need to make sure that if the user stops / reloads the page it won't mess things up.

  • Comment on Re: Wait ... Loading ... message in Perl/CGI

Replies are listed 'Best First'.
Re^2: Wait ... Loading ... message in Perl/CGI
by convenientstore (Pilgrim) on Jan 26, 2008 at 04:01 UTC
    I have always wanted to do this on regular script (none html)
    can someone please let me know how to do this the right way?
    my incorrect version is
    use strict; sub clear_screen { system("clear"); print "wait......................\n"; } sub doit { my $yahoo; while ($yahoo < 100) { clear_screen(); $yahoo++; } print "\$yahoo is $yahoo\n"; } doit();
      You have to learn about fork-ing and managing child processes. Here's some example code:

      use POSIX qw(:sys_wait_h); sub doit { my $pid = fork(); unless (defined($pid)) { die "unable to fork: $!\n"; } if ($pid) { # parent # wait for child to finish and display waiting message my $start = time; while (1) { print "time spent waiting: ", time - $start, "\n"; last if (waitpid($pid, WNOHANG) > 0); sleep(2); } # child process has terminated # read results from file open(R, "<results-from-child-process"); while (<R>) { ... process results... }; close(R); } else { # child # perform time consuming computation here. ... # leave results in some file open(R, ">results-from-child-process"); print R ...; close(R); exit(0); } }
        thanks~ going to try this today and get back to you.