
Go backward to 4.3 CGI Server Side Include Topic
Go up to 4 Major Topics
Go forward to 4.5 Form Processing
4.4 CGI Introduction to Perl Topic #2
The purpose of this section is to continue the introduction of Perl
programming.
This topic will also lead to something useful for CGI programming.
It will help with debugging.
One of the major problems in getting CGI programs to run is the detail
that they run in a different environment than when debugging the program.
The idea of this lab is to make the environments as much a like as
possible.
It is also the plan of this lab to get you to write more Perl programs,
so, even if you find something quite like this lab on the Internet, I
would like
your group to write most of the code anyway.
But -- please look at what is
available and if you find something useful, do look at the code and see
how it was done.
- Look at the environment as provided to your program when run at the
command line. To do this use the
env
command.
- Look at the environment as provided to your program when run
as a CGI program. To do this use the program at
env.pl What are the differences?
#!/bin/sh
echo "Content-type: text/plain"
echo ""
echo ""
env
- Find out how CGI programs use the standard input.
- Read up on subroutines and passing arguments in Perl. See Learning Perl by Schwartz, & Christansen
Chapter 8, "Functions", Pages 92 - 100. Also see Programming Perl by Wall, Christansen, & Schwartz Chapter
2,
"The Gory Details" (not all of it) pages 111 - 121.
- Look at details of (and you are welcome to use) subroutine
parse_form_data
CGI Programming by Gundavaram
On the web at O'Reilly pages 64-67.
- You may want to look at reading and writing files again.
- Write a little "test" programs for accessing values in the
environment.
Write a Perl subprogram that can save and restore passed parameters
to a cgi program. Modify
common.pl
or write your own subprogram that
usually inputs, to a common format, the data passed to a cgi program with
the following additions.
- If the program is run from the shell, it reads in the values
previously
stored in the file saved-arguments. A program can look at the
environment
t variables to determine
if it is being run in the shell. (Environment variable SHELL
would be a good choice.)
- If the subroutine is called from a program running because it was
invoked by a web server, it will process the data normally, but prior
to returning, it will write out to a file (saved-arguments) all of
the passed parameters.
- If the file saved-arguments does not exist,
the program invoked by
httpd
will behave as common.pl did
originally.
- Also provide a conditional print ability, so that if using the
saved environment, additional debug printouts can be included. This can
be just a global variable or a subroutine, your choice.
The purpose of this program is to simplify debugging. It should allow you
to
execute most programs as shell programs with the same environment
"functionally" as when the program is run by the
Hyper Text Transport Protocol Daemon (HTTPD).
Turn in your group's report (only one copy please) marked as follows:
- Louis Taber
- CSC266 Topic: 4.4: Perl 2.
- Your group letter.
- Your group member's names.
- A printout of your Perl subroutine file.
- A printout of a saved environment.
- Suggestions on lab.
Instructor: ltaber@pima.edu** Red's Home page** The Pima College Site
