HTTP header issues with Perl CGI module
I am troubleshooting a Perl script which uses the CGI module. My difficulty is that I need to parse the parameters that the browser passes to the CGI script, and generate one of several possible HTTP header types based on the parameters provided. (Specifically, the request is generated when the user activates a scroll button on the web page. If the user scrolls past the end of the array on the server-side database, I want the CGI script to respond by generating an HTTP redirect header.)
My problem: the CGI module appears to require that I explicitly generate a header immediately after the "use CGI" statement, and before I call any other CGI module functions. If I do not do this, then the Apache server generates a default HTTP header that will precede the header that I ultimately generate from my program. And the default header will have a type of "text/plain." The result is that my HTML page is displayed as text by the browser, including the HTTP header that I intended to be the HTTP header.
I tried to get around this by writing Perl code to parse the CGI script parameters. Unfortunately, the server apparently does not pass the CGI parameters to the Perl script through the command-line; the parameters are accessible only through functions in the CGI module. And this takes me right back to my original problem: the CGI module requires that I generate a header before using these functions.