开发者

get function in perl w/ website does not produce a value inside the perl script

开发者 https://www.devze.com 2023-04-08 18:15 出处:网络
I\'m trying to get index.pl?home=home to produce the value \'home\' within my perl script, or home=anything to produce \'anything\'.

I'm trying to get index.pl?home=home to produce the value 'home' within my perl script, or home=anything to produce 'anything'.

For some reason I'm not using the GET method correctly.

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

What am I doing wrong? I've searched and searched for this SP开发者_JS百科ECIFIC answer...


Add a $cgi->header(); to your script. You're most probably running into a "Premature end of script headers" error:

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

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

Check your error_log for details.


Your code works fine for me. My full script looks like this:

#!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";

(I'm on Windows, but that shouldn't matter.)

When I visit http://localhost/stack.pl?home=xx I see:

Hello world
Hello xx world
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号