HELP! * GREY=local Full HTML for

LOCAL foilset Introduction to Perl Programming: a Stroll Through Perl

Given by Nancy J. McCracken at ECS400 Senior Undergraduate Course on Spring Semester 1996. Foils prepared 27 February 1996
Abstract * Foil Index for this file

See also color IMAGE
Text: Learning PERL (the Llama book), Randal L. Schwartz, OšReilly & Associates, 1993.
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.

Table of Contents for full HTML of Introduction to Perl Programming: a Stroll Through Perl


1 Introduction to PERL Programming:
a Stroll Through Perl
from "Learning Perl" by Randal L. Schwartz

2 PERL4
3 The Simplest Program: Hello, World!
4 Scalar Variables and Keyboard Input
5 Conditional and Comparison
6 While Loop
7 Arrays, also known as lists
8 Associative arrays
9 Regular Expressions and String Matching
10 Substitute and Translate Operators
11 Subroutines
12 Reading Files
13 Sending commands to the operating system
14 Formatting output and using file names
15 Further Topics

This table of Contents Abstract



HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 1 Introduction to PERL Programming:
a Stroll Through Perl
from "Learning Perl" by Randal L. Schwartz

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * See also color IMAGE
Full HTML Index
Nancy McCracken
NPAC
Syracuse University
111 College Place
Syracuse NY 13244-4100
February 5, 1996
Click here for body text

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 2 PERL4

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * See also color IMAGE
Full HTML Index
Text: Learning PERL (the Llama book), Randal L. Schwartz, OšReilly & Associates, 1993.
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.

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 3 The Simplest Program: Hello, World!

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * See also color IMAGE
Full HTML Index
Each Perl program is in a Unix file, with executable permission, and is executed by typing the name of the file as a command.

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 4 Scalar Variables and Keyboard Input

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * See also color IMAGE
Full HTML Index
This program uses a scalar variable, which always starts with a $, prompts for input, reads the name, and prints hello.

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 5 Conditional and Comparison

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * See also color IMAGE
Full HTML Index
This program prints a special greeting for Randal, and an ordinary one for everybody else.

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 6 While Loop

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * See also color IMAGE
Full HTML Index
This program asks everyone, except for Randal, for a secret password.

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 7 Arrays, also known as lists

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * See also color IMAGE
Full HTML Index
This program uses an array variable, which must start with @, to hold several secret passwords.

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 8 Associative arrays

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * Critical Information in IMAGE
Full HTML Index
Associative arrays, variables start with %, are tables with keywords and values and are used here to give each person their own password.

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 9 Regular Expressions and String Matching

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * Critical Information in IMAGE
Full HTML Index
Accept input name in varying formats by matching strings that are case insensitive and longer, such as Randal L. Schwartz

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 10 Substitute and Translate Operators

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * Critical Information in IMAGE
Full HTML Index
Truncate all input names to the first name and translate to all lower case.

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 11 Subroutines

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * Critical Information in IMAGE
Full HTML Index
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 &, for example &good_word($name,$guess);

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 12 Reading Files

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * See also color IMAGE
Full HTML Index
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.

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 13 Sending commands to the operating system

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * See also color IMAGE
Full HTML Index
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.

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 14 Formatting output and using file names

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * See also color IMAGE
Full HTML Index
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.

HELP! * GREY=local HTML version of LOCAL Foils prepared 27 February 1996

Foil 15 Further Topics

From Introduction to Perl ECS400 Senior Undergraduate Course -- Spring Semester 1996. * See also color IMAGE
Full HTML Index
Further examples in Chapter 1 of Learning Pearl discuss
  • renaming files
  • keeping an associative table in a file database
Final programs are on page 32.

Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Feb 19 1997