in reply to CGI::header() & What's !DOCTYPE..?

Thanks for all the help on DTDs.. enlightening.

Here's a fairly bare-bones version of my script that I have confirmed still exhibits the same behavior:

#This script recieves valid data POSTed to it from an HTML form. use CGI qw/:standard/; use CGI::Pretty; ### HERE IS THE PROBLEM: ############################################# +######### ##Un-comment one or the other of these next two lines to reproduce the + problem# # + # #print "Content-type: text/html\n\n"; #Using this line works beautifu +lly. # # + # #print header(); #Using this line stalls the browser. + # # + # ###################################################################### +######### print "<HTML><HEAD><TITLE>Confirmation</TITLE></HEAD><BODY BGCOLOR=\"3 +355ff\">"; print h1('Header'); print h4('Trying sysread..'); $data = try_sysread(); print $data; print h4('Sysread done..'); print end_html; exit; ########## sub try_sysread(){ sysread(STDIN,$d,$ENV{CONTENT_LENGTH}); return $d; };
params() was a good idea, but then I tried Vars() and it works beautifully with any decent header, once I noticed that you have to import the *:cgi-lib* functions from CGI.
Assuming I hear of nothing dangerous or evil about Vars(), I'll use it.

I still don't know why this sysread thing happened, though.. any ideas would still be appreciated, if only for the joy of abstract knowledge (especially for the joy of abstract knowledge.. practical knowledge hurts when you don't have it.)

==========

Can an atheist be insured against acts of God?

Replies are listed 'Best First'.
Re: The code, a solution, and many many thanks
by chromatic (Archbishop) on Mar 16, 2001 at 09:20 UTC
    Looking through the code of CGI.pm, when you call header(), it calls self_or_default(). That particular function is a rather ugly way of allowing a procedural and object-oriented interface.

    Anyhow, self_or_default() winds up calling CGI::new() if you're using the procedural interface. This is important, because new() calls init(). As I predicted earlier, that's what calls sysread. It slurps up $ENV{'CONTENT_LENGTH'} worth of bytes from STDIN.

    When you attempt to read from STDIN, there's nothing there. So Perl helpfully waits for something -- anything -- which never arrives.

    As for Vars() versus param(), Vars() is an old, deprecated, backwards-compatible function that bridges the gap between Perl 4 functionality and Perl 5. param() is the wave of the future! It's worth learning; it's flexible and powerful.