Good day bretheren. I am trying to use mod CGI with POST input and am getting a stange error. Here is the (simplified) code:
#!/usr/bin/perl -w use strict; use HTTP::Daemon; use CGI qw/:standard/; my $d = HTTP::Daemon->new(LocalPort => 8080) || die; while (my $c = $d->accept) { while (my $r = $c->get_request) { my $uri = $r->uri; $ENV{REQUEST_METHOD} = $r->method; $ENV{CONTENT_TYPE} = join('; ', $r->content_type) || ''; $ENV{CONTENT_LENGTH} = $r->content_length || ''; $ENV{SCRIPT_NAME} = $uri->path || 1; $ENV{QUERY_STRING} = $uri->query || ''; my $q = new CGI; my $reply; my $scriptname = $ENV{'SCRIPT_NAME'}; #$q = new CGI; if ($scriptname =~ /start/) { $reply = $q->header; open(IN,"test.htm") or die "Can't open input: $!\n"; while(<IN>) { $reply .= $_; } close IN; } elsif ($scriptname eq '/process') { my @params = $q->param; $reply = $q->header; $reply .= $q->start_html.$q->h2("Parameters").join('<br>', +@params).$q->end_html; } $c->send_response($reply); } $c->close; undef($c); }
and here is the test.htm it uses
<html> <body> <form method="post" action="process" enctype="multipart/form-data"> <input type="checkbox" name="cb" value="on" /><input type="text" name= +"label" value="foobar" size="40" /> <input type="submit" name=".submit" /> </form> </body> </html>
I get the initial page with localhost:8080/start. Upon clicking SUBMIT I get error Use of uninitialized value in pattern match (m//) at (eval 22)[C:/Perl/site/lib/CGI.pm:829] line 4.. If I step through the code with the (Komodo) debugger, it goes into an infinite wait at my $q = new CGI;. I found that if I delete the enctype argument from the form tag in the htm file, I get no error and the infinite wait, debugger or no.

I found this thread that seems to discuss a similar problem, but it's talking about file uploads and anyway is four years old so I would think that this particular bug has been worked out by now.

Anyone know what the problem is here?

Thx...Steve

Edit: g0n - corrected link format

Update: In the code above I commented out the second CGI constructor, a mistake caught by Chromatic. But that didn't fix the problem. Also based on his opinion that CGI didn't have the proper filehandle, and the old thread linked above, I tried inserting local *main::STDIN = $c; right before the CGI constructor, and that didn't fix things either.

In reply to Mod CGI problems with POST by cormanaz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.