N
Nigel
Hi there,
I hope you can help - I'm writing a perl program and I want it report
back to the browser
on its progress. I read the perl faq and saw that by setting $| true
the buffer would be
flushed each time I printed instead of waiting until the program
terminates. But I can't
get it to work.
I'm expecting the web page to say that it's on the job, then every
second (for 10 seconds) to say Please Wait and then at the end to say
it's finished. But what happens is I wait ten seconds for a response
and the whole lot appears at once. Any advice would be VERY welcome.
Here is my VERY basic program...
#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qwstandard escape escapeHTML);
# Force the buffer to flush
$|++;
my $i;
print << "EOF";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test Buffer</title>
</head>
<body>
Working on it!<br />
EOF
for ($i=0;$i<10;$i++) {
print "Please wait!<br />\n";
sleep 1;
};
print << "EOF";
All Done!
</body>
</html>
EOF
exit (0);
I hope you can help - I'm writing a perl program and I want it report
back to the browser
on its progress. I read the perl faq and saw that by setting $| true
the buffer would be
flushed each time I printed instead of waiting until the program
terminates. But I can't
get it to work.
I'm expecting the web page to say that it's on the job, then every
second (for 10 seconds) to say Please Wait and then at the end to say
it's finished. But what happens is I wait ten seconds for a response
and the whole lot appears at once. Any advice would be VERY welcome.
Here is my VERY basic program...
#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qwstandard escape escapeHTML);
# Force the buffer to flush
$|++;
my $i;
print << "EOF";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test Buffer</title>
</head>
<body>
Working on it!<br />
EOF
for ($i=0;$i<10;$i++) {
print "Please wait!<br />\n";
sleep 1;
};
print << "EOF";
All Done!
</body>
</html>
EOF
exit (0);