![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Perl CGl Programming: No experience required.
Setting the Environment VariablesEnvironment variables can be set by any program. However, programs can run programs, and the environment of a parent application also can be made available to a child application. This concept is especially important in operating systems such as Windows 95, NT, and UNIX, which can run more than one program at a time.
The reason you can set environment variables from the command line and then read them from a program is because the command line itself is a programcmd .exe or command.com in the Windows world and the shell in UNIXand it is the parent of every program you run. Similarly, if your program adds to the environment any other variable settings, this information is available to any child applications it spawns.
So, if the child is written to know in advance what the names of its parents environment variables are, it can also read and process the values in them (see Figure 3.3). The parent can see the changes, too. It amounts to a stripped-down version of interprocess communication (IPC), which is how very sophisticated software systems coordinate themselves.
The CGI pipeline allows you to regard the Web server as the parent application and your Perl program as the child. Thus, whatever the server places in its environment comes down the pipeline to you. CGI Environment VariablesWhen your Web server starts, it fills in a group of environment variables that describe some of its characteristics. Then, when a clienta visitor to your siteconnects with the server, other environment variables are filled in with information about the connection: who, what, where, when, and so on. See Table 3.1 for a listing of some of the common CGI environment variables.
In this skill, you will write a Perl script that grabs some of the most common variables and displays them on a Web page. Some New Perl ConceptsIn the process of designing a Perl program to print CGI environment variables to a Web page, youll learn the details of Perl associative arrays and two new tools:
An associative array is very much like a normal array, except that there are two values at every index position instead of one. The first value is known as the key and it is used by Perl in an internal index of the array. The internal index is constructed by hashing the keys, an efficient method of storage that makes lookups very fast.
Associative arrays usually are used for long lookup tables, where a short key can be used to refer to a long description. You will be doing just that in the program youre about to write. As mentioned previously, associative array variables introduce a new Perl notationthey always start with the percent sign (%). Well discuss the each and while statements after you finish with the program. Displaying the CGI EnvironmentIt will be easier to understand the CGI environment if you can see it, and the interaction between the Web server and a Perl script is best illustrated with a Web page. Lets write a Perl program that displays some common CGI environment variables in an HTML document.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |