in reply to Re: $ENV{'REQUEST_METHOD'} undefined?
in thread $ENV{'REQUEST_METHOD'} undefined?

I don't quite understand. I have updated the code (to the best of my ability) to use the CGI module. Perhaps, I am leaving something out. Keep in mind that the actual script will accept any number of parameters through an HTML form.

#!C:\Perl\bin\perl.exe use strict; use warnings; use CGI; my $req_meth = CGI->request_method(); sub readPostInput() { my (%searchField, $buffer, $pair, @pairs); if ($req_meth eq 'POST') { read (STDIN,$buffer,$ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { my ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/e +g; $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg +; $searchField{ $name } = $value; } } } my %postInputs = readPostInput(); print "Content-type: text/html\n\n"; print "Complete :: $req_meth";

After these changes I still receive the same error.

Replies are listed 'Best First'.
Re^3: $ENV{'REQUEST_METHOD'} undefined?
by moritz (Cardinal) on Nov 30, 2009 at 12:21 UTC
    use strict; use warnings; use CGI; my $req_meth = CGI->request_method(); my %postInputs = CGI->Vars; ...

    Still you haven't answered the most important question: Is the script run as a CGI script? That is, is there a web server that executes it with the CGI protocol?

    Perl 6 - links to (nearly) everything that is Perl 6.

      This script, I believe, is not run as a CGI script. I say this because I haven't yet used the CGI module in it. HTML is ouput using templates, and any data is stored into DAT files simply by opening them and writing to them.

      I hope that answers your question.

        Yes, it answers my question. And it explains why $ENV{'REQUEST_METHOD'} is not defined - because nobody defined it. Usually the web server does that, when you run the program as CGI.

        So you're using a script in context it was not made for. The fix is to run it in the right context, which means through a web server as CGI. (Using the CGI is module is only a symptom for a CGI environment, and not necessarily related to it).