After spending the past few months understanding Perl'svariables, operators and functions, it's time to start writing Perlprograms for the Web. This week, Perl 101 introduces you to the basics ofCGI scripting, and also teaches you how to use a new type of Perl variable,the hash.
And when you view this page in your browser (assuming you've
placed it in the appropriate place with the appropriate permissions, and that the file is called "good.cgi") by surfing to http://localhost/cgi-bin/good.cgi, you'll see this:
God, I'm good!
Let's dissect this a bit. The first line of the script is one
you'll have to get used to seeing in all your CGI scripts, as it tells the browser how to render the data that follows. In this case, we're telling the browser to render it as HTML text.
Note the two line breaks following the Content-Type statement - forgetting these is one of the most common mistakes Perl newbies make, and it's the cause of a whole slew of error messages.
Our next line is a print() statement which simply outputs some HTML-formatted text - this is what the browser will see.
You can also use variables when generating your page - as the next example demonstrates: