Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Progress bar for CGI by reading a file

by sara2005 (Scribe)
on Jun 16, 2006 at 23:24 UTC ( [id://555906] : perlquestion . print w/replies, xml ) Need Help??

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

Hi Monks,

I run CGI programs for executing long processes (thanks to merlyn ), which is working fine in Unix.

I got a little greedy :) and wanted to implement a progress bar, which should read a status file in the server and display the percentage complete in the web browser. The status file can be as simple as

task name completed=45%

If this can be translated in the browser as

Executing task: <task name> #########--------------- (this is % complete in bars)

Unfortunately, I was not able to find any modules in CPAN that can achieve this. Can someone provide some hints on how to get this done?

Replies are listed 'Best First'.
Re: Progress bar for CGI by reading a file
by freakingwildchild (Scribe) on Jun 17, 2006 at 05:22 UTC
    Maybe this might help you out CGI::ProgressBar. Example code:
    use strict; use warnings; use CGI::ProgressBar qw/:standard/; $| = 1; # Do not buffer output print header, start_html( -title=>'A Simple Example', -style=>{ -src => '', # You can override the ba +r style here -code => '', # or inline, here. } ), h1('A Simple Example'), p('This example will update a JS/CSS progress bar.'), progress_bar( -from=>1, -to=>100 ); # We're set to go. for (1..10){ print update_progress_bar; # Simulate being busy: sleep 1; } # Now we're done, get rid of the bar: print hide_progress_bar; print p('All done.'); print end_html; exit;
Re: Progress bar for CGI by reading a file
by lima1 (Curate) on Jun 17, 2006 at 00:11 UTC
    I'm quite sure that any of this myriad of new AJAX libraries has something like this. The rough idea: you have to generate and update a XML file containing the percentage in your perl code and some javascript stuff updates your webpage.

    google for it, I think a progress bar is the AJAX "Hello World" program ;)

Re: Progress bar for CGI by reading a file
by TedPride (Priest) on Jun 17, 2006 at 01:25 UTC
    Have your script update a small HTML file every so often with the current percentage, and run it in a frames layout, with one frame being the main script and the other (on refresh every 5 sec or so) the percentage file.