Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

HTML Display

by Gwalchmai (Novice)
on Sep 17, 2003 at 18:51 UTC ( [id://292211]=perlquestion: print w/replies, xml ) Need Help??

Gwalchmai has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Perlers,

I have created the following sub that uses CGI ':standard' coding.

The sub is called several times during the program.

When the program runs, each display is being tacked onto the bottom of the previous. Is there any way to clear the browser screen so that each sub run prints to a clean screen?

sub screenDisplay { my ( $thread, $status ) = @_; print header, start_html('Distributed Search Progress'), h1('Search in progress ... Please wait.'), $progress[$status], "Thread: $thread\n", hr, end_html; }

edit by thelenm: added code tags

Replies are listed 'Best First'.
Re: HTML Display
by jdtoronto (Prior) on Sep 17, 2003 at 19:07 UTC
Re: HTML Display
by perrin (Chancellor) on Sep 17, 2003 at 19:12 UTC
      Should have looked shouldn't I! Merlyn has a LOT of very useful columns!

      jdtoronto

Generating multiple pages from a single CGi script
by jonadab (Parson) on Sep 17, 2003 at 19:02 UTC

    To change the content on the browser side, you need some kind of client-side technology, such as ECMA script ("Javascript") or a plugin. However, what you describe sounds to me like separate pages. Is there some way your script can initially send only the first page, but include a link (and maybe an HTTP refresh) back to the script with an additional parameter that indicates to print the second page, the third page, or whatever? So, if there's no page set, you send page 1 (with a link with page=2), but if the query string says page=3 you send page 3 and a link with page=4. This is the way all the major search engines do it, I think. If the query string says page=n, you send page n with a link to page=n+1


    $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
Re: HTML Display
by Plankton (Vicar) on Sep 17, 2003 at 19:14 UTC
    You could "poll" from the client-side with Javascript ...
    ... my $JS<<END; function goThere () { document.location="$yourURL"; } function delay () { setInterval ( "goThere()", 6000 ); } END ... print start_html( ..., -script=>$JS, ... ); ...

    Plankton: 1% Evil, 99% Hot Gas.
      OK, yes it could be done that way. But why would you? Using your method assumes that JavaScript is enabled in the browser. My WEB sites record enough browsers without JS activated to make it worth our while to NOT use JS. Only place we use it is for some form validation, it makes things faster on the client side, but we always have ful validation in our Perl scripts to do two things:
    • Make sure our forms and JS are not tampered with
    • Validate where client has no JS. By using your method you would exclude a fair percentage of browsers.

      jdtoronto

Re: HTML Display
by sunadmn (Curate) on Sep 17, 2003 at 20:36 UTC
    I would have to say the way I could see this being done would be to inbed a meta refresh tag into the html output and just point to some sort of incremental page system.I.E. bla.html -> bla1.html -> bla2.html and so on. -Stephen
      Yes, that would work too. But the question remains, as I asked of another contributor - why do it that way? It would mean creating a series of static documents.

      The script is running, why not let it deal with the issue and keep code and/or HTML writing to a minimum?

      jdtoronto

        I agree that it would make more sense to have the perl handle this, but I am not quit sure how I would do it. Let me do some diggin and see what I can come up with, also if you find a good solution in the meantime please share with me as I would be very curious as to what you came up with.
        Stephen
Re: HTML Display
by Gwalchmai (Novice) on Sep 26, 2003 at 12:33 UTC
    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

Re: HTML Display
by PodMaster (Abbot) on Sep 26, 2003 at 13:00 UTC
    Check out http://openthought.net/ and especially the demo.

    Don't assume javascript is enabled, demand it :)

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://292211]
Approved by jdtoronto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-24 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found