Building a CGI Script, From Form to Response

The best way to learn how to code CGI is to go ahead and do it, so let's do it. In this section we'll create a really simple CGI script—the equivalent of Hello, World—using a basic HTML form, Perl for the CGI script, and the CGI.pm module to help put it all together. I'll give you the HTML form to work from, but we'll build up the script itself line by line.

The Form

Listing 16.1 shows the HTML code for a simple HTML form that asks you for your name. Figure 16.2 shows what this form looks like in a Web browser.

Figure 16.2. Hello!

Listing 16.1. The name.html File
 1: <html> 2: <head> 3: <title>Tell ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.