in reply to Re: Wait ... Loading ... message in Perl/CGI
in thread Wait ... Loading ... message in Perl/CGI

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();

Replies are listed 'Best First'.
Re^3: Wait ... Loading ... message in Perl/CGI
by pc88mxer (Vicar) on Jan 26, 2008 at 06:14 UTC
    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.
Re^3: Wait ... Loading ... message in Perl/CGI
by Joost (Canon) on Jan 26, 2008 at 12:59 UTC