http://qs321.pair.com?node_id=294390


in reply to HTML Display

I have a couple of examples that might help explain where I'm at and where I need to get to.

The two examples, attached to this e-mail, represent the development path of the tool I created.

Script "threadTest2.pl" provides the results in the same fashion as your stock ticker. This is easy to send the new information to the user's browser.

Script "threadTest3.pl" displays the items as a group every time an item changes. I can send these groups to the screen with no problem.

What I want to do is find a way to redraw the screen each time a new group is sent to the browser, so it would appear that only the status of the items is changing.

My first thought was to refresh also, but since this is a live program, that is not an option since it would restart the program.

The eventual goal is to put a cancel button below the displayed group that the user could press if the process is taking to long. The program would then cancel all threads that have not completed and continue to process and display the results from the finished threads.

Any thoughts, help or advice would greatly be appreciated.

Thanks,

Doug

### Program: threadTest2.pl ### use threads; use threads::shared; use CGI::Push qw/:standard/; # Shared variables my $progressThread1 : shared = 0; my $progressThread2 : shared = 0; my $progressThread3 : shared = 0; my $progressThread4 : shared = 0; my $progressThread5 : shared = 0; # Arrary of progress text @progress = ( 'No Activity....', 'Connecting.....', 'Searching......', 'Parsing........', 'Finished.......', 'Error..........', ); # Create threads $thr1 = threads->new(\&thread1); $thr2 = threads->new(\&thread2); $thr3 = threads->new(\&thread3); $thr4 = threads->new(\&thread4); $thr5 = threads->new(\&thread5); # Do not end program until all threads have finished $thr1->join(); $thr2->join(); $thr3->join(); $thr4->join(); $thr5->join(); sub thread1 { sleep 6; screenDisplay( 1, 1 ); sleep 2; screenDisplay( 1, 2 ); sleep 4; screenDisplay( 1, 3 ); sleep 5; screenDisplay( 1, 4 ); } sub thread2 { sleep 8; screenDisplay( 2, 1); sleep 2; screenDisplay( 2, 2 ); sleep 4; screenDisplay( 2, 3 ); sleep 5; screenDisplay( 2, 4 ); } sub thread3 { sleep 3; screenDisplay( 3, 1 ); sleep 2; screenDisplay( 3, 2 ); sleep 4; screenDisplay( 3, 3 ); sleep 5; screenDisplay( 3, 4 ); } sub thread4 { sleep 10; screenDisplay( 4, 1 ); sleep 2; screenDisplay( 4, 2 ); sleep 4; screenDisplay( 4, 3 ); sleep 5; screenDisplay( 4, 4 ); } sub thread5 { sleep 1; screenDisplay( 5, 1 ); sleep 2; screenDisplay( 5, 2 ); sleep 4; screenDisplay( 5, 3 ); sleep 5; screenDisplay( 5, 4 ); } sub screenDisplay { my ( $thread, $status ) = @_; print $progress[$status], "Thread: $thread\n"; return undef; } ### Program: threadTest3.pl ### use threads; use threads::shared; use CGI::Push qw/:standard/; # Shared variables my $progressThread1 : shared = 0; my $progressThread2 : shared = 0; my $progressThread3 : shared = 0; my $progressThread4 : shared = 0; my $progressThread5 : shared = 0; # Arrary of site names @sites = ( '', 'Site One', 'Site Two', 'Site Three', 'Site Four', 'Site Five', ); # Arrary of progress text @progress = ( 'No Activity....', 'Connecting.....', 'Searching......', 'Parsing........', 'Finished.......', 'Error..........', ); # Create threads $thr1 = threads->new(\&thread1); $thr2 = threads->new(\&thread2); $thr3 = threads->new(\&thread3); $thr4 = threads->new(\&thread4); $thr5 = threads->new(\&thread5); # Do not end program until all threads have finished $thr1->join(); $thr2->join(); $thr3->join(); $thr4->join(); $thr5->join(); sub thread1 { sleep 6; $progressThread1 = 1; screenDisplay(); sleep 2; $progressThread1 = 2; screenDisplay(); sleep 4; $progressThread1 = 3; screenDisplay(); sleep 5; $progressThread1 = 4; screenDisplay(); } sub thread2 { sleep 8; $progressThread2 = 1; screenDisplay(); sleep 2; $progressThread2 = 2; screenDisplay(); sleep 4; $progressThread2 = 3; screenDisplay(); sleep 5; $progressThread2 = 4; screenDisplay(); } sub thread3 { sleep 3; $progressThread3 = 1; screenDisplay(); sleep 2; $progressThread3 = 2; screenDisplay(); sleep 4; $progressThread3 = 3; screenDisplay(); sleep 5; $progressThread3 = 4; screenDisplay(); } sub thread4 { sleep 10; $progressThread4 = 1; screenDisplay(); sleep 2; $progressThread4 = 2; screenDisplay(); sleep 4; $progressThread4 = 3; screenDisplay(); sleep 5; $progressThread4 = 4; screenDisplay(); } sub thread5 { sleep 1; $progressThread5 = 1; screenDisplay(); sleep 2; $progressThread5 = 2; screenDisplay(); sleep 4; $progressThread5 = 3; screenDisplay(); sleep 5; $progressThread5 = 4; screenDisplay(); } sub screenDisplay { print $progress[$progressThread1], $sites[1], "\n"; print $progress[$progressThread2], $sites[2], "\n"; print $progress[$progressThread3], $sites[3], "\n"; print $progress[$progressThread4], $sites[4], "\n"; print $progress[$progressThread5], $sites[5], "\n\n"; }

20030926 Edit by Corion: Fixed formatting