Perl and CGI (Common Gateway Interface)
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 lan-guage 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.6 and examine several practical examples that use Perl for Internet programming.
The Common Gateway Interface (CGI) is a standard protocol 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 due to its power, flexi-bility and availability of several preexisting programs.
Figure 27.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 Web-master 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 (such as .cgi or .pl) and/or located within a special directory (such as 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 Chapter 19), XML (see Chapter 20), etc.
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, typ-ically 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 dis-played on the screen, but may be printed, written to a file, etc.
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 ren-dering. 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.
Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.