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

Hi everyone!
I'm newbie in cgi-perl programming and I have such problem:

when cgi script read data, posted from html form with "post" post method, the read sub return zero of readed bytes, but $ENV{'CONTENT_LENGTH'} hold (for example) 7 bytes.

Any idea? Where I'm wrong ?

Here is my html from and cgi script:

=========================== some_file.html --------------------------- <html> <head> </head> <body> <form action="/cgi-bin/script.pl" method="POST"> <input type="text" name="query"> <br> <input type="submit"> </form> </body> </html> ============================== ================================ script.pl: -------------------------------- #!/usr/bin/perl use CGI qw/:standard/; print header; $length = $ENV{'CONTENT_LENGTH'}; $count = read (STDIN, $buffer, $length); print "readed actually: $count, length: $length"; ================================
output in browser:
readed actually: 0, length: 7

Yes, I may solve this problem when getting form input touch CGI.pm, but the code above is correct, isn't it?

Edit by tye, remove PRE tags, other formatting clean-up

Replies are listed 'Best First'.
•Re: I cannot read from STDIN in cgi-styled script
by merlyn (Sage) on Jul 02, 2004 at 14:00 UTC
    Once you've issued "use CGI", then the CGI module is managing your GET/POST data for you, including slurping up STDIN as needed. Look at the param method/routine in the CGI docs to get at your data.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.