2011-09-26 20 views
-1

我試圖讓index.pl?home=home在我的perl腳本或home中生成值'home'=生成任何東西「任何東西」。在perl w /網站中獲取函數不會在perl腳本中產生值

出於某種原因,我沒有正確使用GET方法。

#!/usr/local/bin/perl 
use CGI qw(:standard); 
$cgi = new CGI; 
$home = $cgi->param('home'); 

我在做什麼錯?我已經搜索並搜索了這個具體的答案...

+1

你會得到什麼結果? – clarkb86

+0

好吧,現在它工作得很好,我拿出了一個額外的value = value2鏈接之間,這是導致錯誤! –

回答

1

您的代碼對我來說工作正常。我完整的腳本是這樣的:

#!C:/perl/bin/perl.exe 

use CGI qw(:standard); 
$cgi = new CGI; 
$home = $cgi->param('home'); 

print "Content-Type: text/plain\n"; 
print "\n"; 
print "Hello world\n"; 
print "Hello $home world\n"; 

(我在Windows,但不應該的問題。)

當我訪問http://localhost/stack.pl?home=xx我看到:

Hello world 
Hello xx world 
+0

這正是我所想的,幾乎與我想要做的一樣...但由於某種原因它顯示爲空白值。 –

+0

謝謝,現在它工作得很好。 –

2

添加$cgi->header();到你的腳本。你最有可能運行到一個「Premature end of script headers」錯誤:

#!/usr/local/bin/perl 
use CGI qw(:standard); 
$cgi = new CGI; 
$home = $cgi->param('home'); 

print $cgi->header(); 
print $home 

檢查你的error_log瞭解詳情。