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

Dear Monks,
When I do
my $q = new CGI;
then all STDIN string is read in this call.
I need this string to do something like that
read (STDIN, $query, $ENV{'CONTENT_LENGTH'}); ## process string ....
At the same time I need to have CGI. Is there any way to get STDIN input as is from $q?

Replies are listed 'Best First'.
Re: STDIN from CGI object
by Anonymous Monk on Feb 19, 2011 at 15:05 UTC
      Thanks,
      Do you think it's possible to first read STDIN to a file <FILE> and then call $q = CGI->new(FILE); ?
      Thus I will save unparsed data in FILE and have an unchanged workflow with the CGI object.
        Maybe like this
        SaveStdin('newfile'); open STDIN, '<', 'newfile'; $q = CGI->new;
Re: STDIN from CGI object
by chromatic (Archbishop) on Feb 19, 2011 at 19:18 UTC

    What are you trying to do that you think you need both? There's probably a better way.

Re: STDIN from CGI object
by ikegami (Patriarch) on Feb 19, 2011 at 23:52 UTC

    Do you want to do this because the request body isn't a form? If the request body isn't a form (application/x-www-form-urlencoded or multipart/form-data), then CGI provides the request body in $cgi->param('POSTDATA').

    If you want to do your own form handling, you could set $ENV{CONTENT_TYPE} to application/octet-stream (or whatever) and fetch the request body using $cgi->param('POSTDATA'), or you could read STDIN and set $ENV{CONTENT_LENGTH} to zero before creating the CGI object.

      I have exactly situation (application/x-www-form-urlencoded). So there is still a question how to get STDIN from CGI object.
        That's what the second paragraph is about.