This chapter introduces the Perl interpreter NLM and describes
The Perl interpreter is an NLM that uses RCGI to receive request data, invoke a Perl script, pass the request data to the script, interpret the script's output, and return the generated web pages to the NetWareŽ Web Server to transmit to the client. Click here to view a figure that illustrates this relationship.
The Perl interpreter must be loaded for Perl scripts to be interpreted. To load the interpreter, type:
load perl
The interpreter uses port 8002 by default. To define a port other than the default of 8002, use the -p switch when you load Perl. For example, to use port 8004, type
load perl -p 8004
Before you write a Perl script that generates dynamic Web pages, you should:
If you need detailed information about the Perl language, consult one of these texts.
The Web Server includes a sample script that shows how to use Perl to generate a dynamic Web page. The sample script is stored in the file \WEB\SCRIPTS\CARDSAMP.PL; Click here to view the script.
The script outputs two web pages: a static web page that allows a user to select one of several options and a dynamic Web page generated on the basis of the user's selection.
The script implements a web page that offers users a choice of several greeting cards-a birthday card, an anniversary card, or a thank-you card-and asks users to specify their name and the name of the card's recipient. When the user chooses a card and enters the names, the server returns a new web page showing the chosen card and the personalized greeting. Such a script needs to accomplish the following:
The following subsections describe the Perl statements that perform these functions.
The NetWare Web Server includes a library of Perl routines; click here to see the routines. To include a copy of this library with your C program, use this statement:
require("cgi-lib.pl");The statement shown below invokes the CGI library routine PrintHeader to print an HTTP header on the web page that is returned to the client.
print &PrintHeader;
The PrintHeader function defines the document being created as an HTML document by outputting the following line to the document:
Content-type: text/html\n\n
To read the request data from the browser a script invokes the utility routine ReadParse to read stdin (if the request method was POST) or the query string (if the request method was GET). The script then converts it, and stores it in the list $in.
To invoke ReadParse, use the statement
&ReadParse;
Next, the script returns the web page that allows the user to enter a greeting card choice and specify sender and recipient names. The statement
if ($ENV{"ARGC"} eq "0")determines how many arguments were sent by the browser. Click here to see the statements the script executes to return the static HTML page if the argument count is zero.
If the number of arguments received by the script is not zero, this is a greeting card request. The ReadParse function has placed the returned argument values in the $in array. The script extracts the request type from the array (type 1 is a birthday card, type 2 is an anniversary card, any other value for type is a thank you card) as well as the names of the sender and recipient. Then the script prints out the HTML lines for the card. Click here to see the remainder of the script.
When a user accesses a script, the following actions are performed. (To access the sample script and follow the actions below, point your browser to CARD.PL.)
http://www.webserver.com/perl/card.pl
Click here to view the sample script CARDSAMP.PL.
The Perl interpreter NLM supports most functionality provided by the Perl language. Exceptions include some functions that are valid only in the UNIX environment. Click on the links below to view tables that briefly describe the Perl statements supported by the Perl NLM.
These Perl functions retrieve information about system files from three data structures. Click here to view the names of these data structures and their contents.
Click here to view a table of miscellaneous functions.
The NetWare Web Server provides a library of Perl routines that you can use to manipulate CGI input and format output. Click here to view a table of these routines.
Click here to view a table of Perl functions that are not supported by the NetWare Perl interpreter.