The header and redirect functions of the CGI.pm are used to easily generate HTTP headers for your documents. Every document that is passed via the HTTP protocol is required to contain a header that identifies the content type, and a handful of important basic information. For these examples, we will just be printing headers to the command line of our system, so there's no need for an actual web browser.
First off, lets look at the default output of CGI.pm's header function:
#!/usr/bin/perl -wRunning this program will generate the following output:
use strict;
use CGI qw/:standard/;
my $cgi = new CGI;
print $cgi->header;
Content-Type: text/html; charset=ISO-8859-1As you can see, it's a simple Content-Type statement followed by 2 newlines. The default output of the header function assumes a content-type of HTML, with the ISO-8859-1 standard.
So far, nothing impressive, but keep reading as we explore some of the parameters you can pass into this function, starting with changing the content-type.
