2012-07-18 87 views
1

我正在嘗試創建一個簡單的cgi perl腳本,它從10減少到0;但我似乎無法得到它的工作。它一直告訴我malformed header from script. Bad header=HTTP/1.1 200 OK。我是Perl和CGI腳本的新手,所以我確信它非常簡單。如何在perl中創建一個倒計時cgi腳本?

#!/usr/bin/perl 
use warnings; 
use strict; 

use CGI::Push qw(:standard); 

my $startingCountDown = 10; 

do_push(-next_page => \&refresh, -last_page=> \&lastPage, -delay => 1); 

sub refresh 
{ 
     my ($cgi, $count) = @_; 

     return undef if ($startingCountDown - $count < 0); 

     my $num = $startingCountDown - $count; 
     my $page = $cgi->start_html(); 
     $page .= $cgi->p("The count is $num").end_html(); 
     return $page; 
} 

sub lastPage 
{ 
    my ($cgi, $count) = @_; 
    return start_html()."Blast Off".end_html(); 
} 

如果我從終端運行這個(我的MacBook上)我得到以下錯誤:WARNING: YOUR BROWSER DOESN'T SUPPORT THIS SERVER-PUSH TECHNOLOGY.。我試過在Safari和Chrome中運行這個腳本,但都沒有效果。在這種情況下,我將如何編寫一個功能正常的腳本,從10減少到1,每秒更改一次數字?謝謝。

回答

4

CGI::Push正在使用的「服務器推送」機制(特別是,multipart/x-mixed-replace)未得到廣泛支持。你需要選擇不同的方式來實現這一點;最好的辦法可能是在Javascript中發生倒計時,而不是在服務器端。