FRIENDOFGOD has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: STDIN not working, STDIN hanging
by chromatic (Archbishop) on Jul 01, 2010 at 21:38 UTC
    I believe the above examples should work as is without any Modules.

    They won't, because that's not how the CGI protocol works. If you're going to code a CGI processor by hand, you need to read the specification of the protocol (but don't write your own CGI processor; it's a lot of busy work to work around browser bugs and multiple specifications and server bugs).

Re: STDIN not working, STDIN hanging
by ikegami (Patriarch) on Jul 01, 2010 at 20:45 UTC

    You're reading until the socket is closed, but the client won't close the socket until it has received its reply.

    When responding, list some similar code that works, without CGI.pm or other Module, because I believe the above examples should work as is without any Modules.

    Of course it should work without modules because there's no difference between a script and a module.

    When responding, list some similar code that works

    I'm not about to copy CGI here.

Re: STDIN not working, STDIN hanging
by almut (Canon) on Jul 01, 2010 at 21:03 UTC

    If you really want to reinvent the wheel, you can read the query string as follows:

    my $query; my $req_method = $ENV{REQUEST_METHOD}; if ($req_method eq 'POST') { read STDIN, $query, $ENV{CONTENT_LENGTH}; # <-- } elsif ($req_method eq 'GET') { $query = $ENV{QUERY_STRING}; }

    (But it's not recommended...)

      2010-07-01

      Your example worked,

      and when I replaced,

      read STDIN, $query, $ENV{CONTENT_LENGTH}; # <--

      with,

      $query=<STDIN>; # <--

      it also worked, only when it was loaded directly, but when a form was sent to it, it did the continuous load.

      Works when loaded directly,
      Continuous when form sent to it...

      #! perl my $query; my $req_method = $ENV{REQUEST_METHOD}; if ($req_method eq 'POST') { $query=<STDIN>; print $query; # <-- } # END

      Works when loaded directly,
      Continuous when form sent to it...

      #! perl my $query; if ($ENV{REQUEST_METHOD} eq 'POST') { $query=<STDIN>; print $query; # <-- } # END

      One question is, why did it not work before, when the form was method="post" --

      Your response indicates that <STDIN> handles POST...

      if ($req_method eq 'POST') {$query=<STDIN>;}

      and $ENV{QUERY_STRING} handles GET...

      elsif ($req_method eq 'GET') {$query = $ENV{QUERY_STRING};}

      Did it have anything to do with sockets as the previous response indicates ?

      (But it's not recommended...)

      Why is it not recommended ?

      - Look For God

Re: STDIN not working, STDIN hanging
by AndyZaft (Hermit) on Jul 01, 2010 at 21:10 UTC
    Just wanted to note that using  #! perl is not a good practice as it was recently pointed out to me around here. In this case it is probably not an issue, but #!/usr/bin/env perl is a better choice.