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

Hi,

I'd like to put a progress bar on my webpage, similar to the one coded on this page -

http://javascript.internet.com/messages/progress-bar.html

But I'm not sure how the Perl side should work. My program searches for information on a word, taking a number of minutes to do so. At the moment I have a simple commandline interface which prints out the progress of the program, but I'd like to replace this with a html user interface, where the user can enter the word in the search box and wait for the perl program to return with the result.

Can anyone get me started?
Thanks.

Replies are listed 'Best First'.
Re: Progress Bar controlled via Perl
by edan (Curate) on Aug 22, 2004 at 12:56 UTC
Re: Progress Bar controlled via Perl
by bgreenlee (Friar) on Aug 22, 2004 at 13:21 UTC

    While perhaps not as robust as merlyn's method, there's a much simpler way to do it. Just turn on autoflush ($| = 1) and have your script start outputting to the browser right away. Then update your progress bar every so often while your script runs. Here's a simple example:

    #!perl -w use strict; use CGI; $| = 1; # turn on autoflush print CGI->header; print "Progress: "; for (1..10) { print '.'; sleep 2; } print "\n<br><br>Done!";

    -b

      This method does not always work. For instance, I have been working on a Web App which did something similar. We recently changed the system architecture so that the CGI now sits behind an Apache Reverse Proxy. I cannot get the Reverse Proxy to unbuffer, so this method no longer works. I wonder if a regular Forward Proxy might not do the same thing - probably depends on the proxy server. Just thought I'd mention it.

      --
      edan

Re: Progress Bar controlled via Perl
by Cody Pendant (Prior) on Aug 23, 2004 at 04:41 UTC
    I did something like this just recently, using an animated GIF.

    I print out

    <img src="rotating_thing.gif" name="progress">
    when the process starts, and I print out
    <script> document.images.progress.src='finished.gif'; </script>
    as soon as the process has finished.

    It at least gives the user something to look at while the process is going on.

    Obvious question -- why does your process take so long? Why don't you ask us if we know a way to speed it up?



    ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
    =~y~b-v~a-z~s; print