O'Reilly logo

Learning Perl, Fourth Edition by brian d foy, Tom Phoenix, Randal L. Schwartz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Common Gateway Interface (CGI)

One of the most popular uses for Perl on the Web is in writing CGI programs. These run on a web server to process the results of a form, perform a search, produce dynamic web content, or count the number of accesses to a web page.

The CGI module, which comes with Perl, provides an easy way to access the form parameters and to generate some HTML in responses. (If you don’t want the overhead of the full CGI module, the CGI_Lite module provides access to the form parameters without all the rest.) It may be tempting to skip the module and copy and paste one of the snippets of code that purport to give access to the form parameters, but nearly all of these are buggy.[389] When writing CGI programs, there are several big issues to keep in mind. These make this topic too broad to fully include in this book:[390]

Security, security, security

We can’t overemphasize security. Somewhere around half of the successful attacks on computers around the world involve a security-related bug in a CGI program.

Concurrency issues

It’s easy to have several processes concurrently trying to access a single file or resource.

Standards compliance

No matter how hard you try, you probably won’t be able to test your program thoroughly with more than about 1% or 2% of the web browsers and servers in use today[391] because thousands of programs are available, with new ones popping up every week. The solution is to follow the standards, so your program will work with all of them. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required