Deitel & Associates, Inc. Logo

Back to
digg.png delicious.png blinkit.png furl.png
Internet & World Wide Web How to Program, 3/e
Internet & World Wide Web How to Program, 3/e

© 2004
pages: 1420

Amazon logo

This tutorial presents an introduction to the popular Perl programming language and to the Common Gateway Interface (CGI). Together these can be used to develop powerful Web applications.
[Note: This tutorial is an excerpt (Sections 25.1 and 25.4) of Chapter 25, Perl, from our textbook Internet & World Wide Web How to Program, 3/e. This tutorial may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., INTERNET & WORLD WIDE WEB HOW TO PROGRAM, 3/E, 2004, pp.845-846 and 857-860. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]
25. 1 Introduction to Perl
Practical Extraction and Report Language (Perl) is one of the most widely used languages for Web programming today. Larry Wall began developing this high-level programming language in 1987 while working at Unisys. His initial intent was to create a programming language to monitor large software projects and generate reports. Wall wanted to create a language that would be more powerful than shell scripting and more flexible than C, a language with rich text-processing capabilities and, most of all, a language that would make common programming tasks straightforward and easy. In this chapter, we discuss Perl 5.8 and examine several practical examples that use Perl for Internet programming.
The Common Gateway Interface (CGI) is a standard interface through which users interact with applications on Web servers. Thus, CGI provides a way for clients (e.g., Web browsers) to interface indirectly with applications on the Web server. Because CGI is an interface, it cannot be programmed directly; a script or executable program (commonly called a CGI script) must be executed to interact with it. While CGI scripts can be written in many different programming languages, Perl is commonly used because of its power, its flexibility and the availability of preexisting scripts.
Figure 25.1 illustrates the interaction between client and server when the client requests a document that references a CGI script. Often, CGI scripts process information (e.g., a search-engine query, a credit-card number) gathered from a form. For example, a CGI script might verify credit-card information and notify the client of the results (i.e., accepted or rejected). Permission is granted within the Web server (usually by the Webmaster or the author of the Web site) for specific programs on the server to be executed. These programs are typically designated with a certain filename extension (e.g., .cgi or .pl) or located within a special directory (e.g., cgi-bin). After the application output is sent to the server through CGI, the results may be sent to the client. Information received by the client is usually an HTML or XHTML document, but may contain images, streaming audio, Macromedia Flash files (see Chapters 17-18), XML(see Chapter 20), and so on.
Fig. 25.1 Data path of a typical CGI-based application.
Applications typically interact with the user through standard input and standard output. Standard input is the stream of information received by a program from a user, typically through the keyboard, but also possibly from a file or another input device. Standard output is the information stream presented to the user by an application; it is typically displayed on the screen, but may be printed or written to a file.
For CGI scripts, the standard output is redirected (or piped) through the Common Gateway Interface to the server and then sent over the Internet to a Web browser for rendering. If the server-side script is programmed correctly, the output will be readable by the client. Usually, the output is an HTML or XHTML document that is rendered by a Web browser.
Page 1 | 2 | 3