Just a thought, could it be that the filehandle (STDIN) used in the read function needs to be closed before it is used elsewhere in the script - just like you would close something opened with open(), so perhaps my script should look like this:
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
xyz
.
.
.
close STDIN;
Cheers
A simple test case to check whether STDIN is cleared or not.
Assuming a little file ac.txt with the rather informative text 'Aaron Carter' in it the following code
[af@server Ecotur]$ perl -e 'open IN, "<ac.txt";<IN>;
print tell(IN), "\n"; seek IN, 0, 0;
print tell(IN), "\n"; print read(IN, $x, 20), "\n";
print "$x\n";'
produces the following output:
12
0
12
Aaron Carter
A filehandle is opened, the first record is read, the position in the file is 12, we seek to the beginning, the position is 0, we try to read 20 bytes but get only 12, read put "Aaron Carter" into $x.
If STDIN is not cleared, this code should have the same output:
[af@server Ecotur]$ perl -e '<STDIN>;
print tell(STDIN), "\n"; seek STDIN, 0, 0;
print tell(STDIN), "\n"; print read(STDIN, $x, 20), "\n";
print "$x\n";' < ac.txt
It does. QED. :)
Andreas