get function in perl w/ website does not produce a value inside the perl script
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
精彩评论