Given by Nancy J. McCracken at Jackson State University Mississippi on Fall Semester 97. Foils prepared 3 Sept 1997
Outside Index
Summary of Material
Text: Learning PERL (the Llama book), 2nd ed., Randal L. Schwartz, OšReilly & Associates, 1997. |
PERL4 is an interpreted language that can be regarded as a cross between C, Unix shell, sed and awk. It is a C-based language which can also deal directly with Unix commands and file system and easily do string processing matching. |
In this course, we will concentrate not on using PERL in systems programming, but in using PERL for CGI programming, i.e. implementing programs activated from Web pages. |
In general, we use PERL for tedious high level things which can take a long time to program but not much execution time. For computationally intense programs, we would use a compiled language such as C. |
Our first lecture on Perl will show a series of small programming examples from Chapter 1 of the Learning Perl book, designed to illustrate the main features of the language. Later we will cover each topic in more detail. |
Outside Index Summary of Material
Nancy McCracken |
NPAC |
Syracuse University |
111 College Place |
Syracuse NY 13244-4100 |
September 5, 1997 |
Click here for body text |
Text: Learning PERL (the Llama book), 2nd ed., Randal L. Schwartz, OšReilly & Associates, 1997. |
PERL4 is an interpreted language that can be regarded as a cross between C, Unix shell, sed and awk. It is a C-based language which can also deal directly with Unix commands and file system and easily do string processing matching. |
In this course, we will concentrate not on using PERL in systems programming, but in using PERL for CGI programming, i.e. implementing programs activated from Web pages. |
In general, we use PERL for tedious high level things which can take a long time to program but not much execution time. For computationally intense programs, we would use a compiled language such as C. |
Our first lecture on Perl will show a series of small programming examples from Chapter 1 of the Learning Perl book, designed to illustrate the main features of the language. Later we will cover each topic in more detail. |
Each Perl program is in a Unix file, with executable permission, and is executed by typing the name of the file as a command. |
This program uses a scalar variable, which always starts with a $, prompts for input, reads the name, and prints hello. |
This program prints a special greeting for Randal, and an ordinary one for everybody else. |
This program asks everyone, except for Randal, for a secret password. |
This program uses an array variable, which must start with @, to hold several secret passwords. |
Associative arrays, variables start with %, are tables with keywords and values and are used here to give each person their own password. |
Accept input name in varying formats by matching strings that are case insensitive and longer, such as Randal L. Schwartz |
Truncate all input names to the first name and translate to all lower case. |
All subroutines in Perl have parameters and return a result, the value of the last expression before the return. Undeclared names refer to names in the outer program (global). The subroutine is called with its parameters, for example good_word($name,$guess); |
A file (or I/O channel) is referred to by a "filehandle". (Perl automatically creates filehandles STDIN, STDOUT and STDERR.) We choose to keep our password table in a file with one word per line, alternating keys and values. |
If the wrong person guesses a password, we can send a mail message by issuing the mail command. The pipe symbol is used in the file name to indicate a command. |
A format statement can be associated with each file handle and used for writing to that channel. The format name is the name of the file handle - there can can also be another special format for labelling the tops of output pages. |
Further examples in Chapter 1 of Learning Pearl discuss
|
Final programs are on page 28. |