Networking Chapter 9 Homework Perl Allows You Todefine Subroutine With The Comparison Conditions Used Sort Numeric

subject Type Homework Help
subject Pages 9
subject Words 2853
subject Authors Michael Palmer

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
A Guide to Unix Using Linux, Fourth Edition 9-1
Chapter 9
Perl and CGI Programming
At a Glance
Instructor’s Manual Table of Contents
Overview
Objectives
Teaching Tips
Quick Quizzes
page-pf2
A Guide to Unix Using Linux, Fourth Edition 9-2
Lecture Notes
Overview
Chapter 9 offers an introduction to Perl and CGI programming. The chapter covers the
basics of the Perl language, including data types, a few control structures, and some tips
Chapter Objectives
Understand the basics of the Perl language
Identify and use data types in Perl scripts
Understand differences between the Awk program and Perl programming
Access disk files in Perl
Teaching Tips
Introduction to Perl
1. Provide a brief introduction to the Perl language. Emphasize the following points:
a. Perl stands for Practical Extraction and Report Language.
Teaching
Note that “Practical Extraction and Report Language” is actually a bacronym.
Perl was originally named "Pearl," after the Parable of the Pearl from the Gospel
of Matthew. When Larry Wall discovered the existing PEARL programming
page-pf3
A Guide to Unix Using Linux, Fourth Edition 9-3
According to Wikipedia, “Programming Perl, published by O'Reilly Media,
b. Perl is a free scripting language.
c. Perl runs on many operating systems, including UNIX, Linux, Windows, and
Mac OS X.
d. Perl can be used to manipulate text, display output, handle mathematical
processes, and work with files.
e. Perl is typically used for generating reports and Web programming.
Note that “Perl has several mottos that convey aspects of its design and use. One
is There's more than one way to do it. (TIMTOWTDI, usually pronounced 'Tim
2. Use examples example1.pl through example4.pl in the book to help students familiarize
themselves with Perl’s syntax (see Figures 9-1 through 9-3).
4. Use example5.pl to show how to use the if-else statement.
page-pf4
A Guide to Unix Using Linux, Fourth Edition 9-4
Identifying Data Types
1. Explain that in Perl, data can be represented in a variety of ways, including:
a. Variables and constants
b. Scalars
c. Numbers
Variables and Constants
1. Variables are symbolic names that represent values stored in memory. Use one or more
examples to illustrate how variables are used in Perl.
2. Constants do not change value as the program runs. Use one or more examples to show
how constants are used in Perl.
Scalars
2. Stress that in Perl, scalar names begin with a dollar sign ($).
3. Use a few examples to show how to assign values to scalar variables in Perl.
Numbers
1. Explain that numbers are stored inside the computer as: signed integers (e.g., 14321) or
double-precision, floating-point values (e.g., 56.85).
3. Explain that for legibility purposes, Perl allows the use of the underscore (_) character
within literal numbers specified in a program (for example, 5_456_678_901).
4. Stress that the character sequence 0x is used to express hexadecimal constants.
Strings
1. Explain that strings are sequences of any types of characters.
page-pf5
A Guide to Unix Using Linux, Fourth Edition 9-5
2. Note that in Perl, strings are delimited by single quotes or double quotes. Make sure
4. Use example7.pl to show how to use control and escape characters in a Perl script.
Arrays
1. Explain that arrays are variables that store an ordered list of scalar values. Explain that
3. Use example8.pl to show how to use arrays in Perl.
Hashes
1. Explain that a hash is a variable that represents a set of key/value pairs. Note that hash
variables are preceded by a percent character (%) when they are assigned values. Use a
3. Use example9.pl to show how to use a hash variable in a Perl script.
Quick Quiz 1
1. ____________________ (Perl) is a free script language that runs on many operating
systems, including UNIX, Linux, Windows, and Mac OS X.
page-pf6
2. A(n) ____________________ is a simple variable that holds a number or a string.
3. Arrays are variables that store an ordered list of scalar values that are accessed with
numeric subscripts, starting at ____________________.
4. A(n) ____________________ is a variable that represents a set of key/value pairs.
Perl Versus the Awk Program
1. Describe the similarities and differences between Perl and the Awk program. Stress that
2. Use awkcom.a and perlcom.pl to compare and contrast an Awk program with a Perl
program. Figures 9-6 and 9-7 show the output of these programs.
3. While explaining the perlcom.pl program, devote some time to discuss the use of the
diamond operator (<>).
How Perl Accesses Disk Files
1. Explain that Perl uses filehandles to reference files. Note that a filehandle is a name for
3. Explain that you must issue an open before you can access a file, except when the file
name is passed through ARGV[0].
page-pf7
A Guide to Unix Using Linux, Fourth Edition 9-7
4. Note that Perl provides three standard filehandles: STDIN, STDOUT, and STDERR.
Using Perl to Sort
1. Explain that Perl provides a powerful and flexible sort operator, which can be used to
Using Perl to Sort Alphanumeric Fields
1. Use examples perlsort1.pl and perlsort2.pl to show how to sort alphanumeric fields in
Perl.
Using Perl to Sort Numeric Fields
2. Use an example to show how to use the spaceship operator (<=>) to sort numeric
fields.
4. Use examples perlsort3.pl and perlsort4.pl to illustrate the concepts presented in this
Quick Quiz 2
1. Both Perl and Awk use the ____________________ sign to specify a comment line.
#
2. The <> symbol is called the ____________________ operator.
page-pf8
3. A(n) ____________________ is the name for an I/O connection between your Perl
program and the operating system, and it can be used inside your program to open, read,
write, and close the file.
4. A(n) ____________________ is a segment of code often used over and over again that
can be internal or external to a program.
Setting Up a Web Page
1. Explain the role of HTML in Web page creation. Introduce the following terms: tag,
hyperlink, Web server, loopback, localhost.
Apache, which is offered through the Apache Software Foundation, is really
Creating a Simple Web Page
1. Explain that to create a simple Web page, you can use a visual WYSIWYG editor or a
plain text editor.
2. Use the example provided in the book and Figure 9-9 to show how to create and
preview a simple Web page.
CGI Overview
2. Explain that CGI is a protocol governing how browsers and servers communicate.
page-pf9
A Guide to Unix Using Linux, Fourth Edition 9-9
3. Exchanging and processing a form typically involves the following:
a. Using CGI for communication between the client’s Web browser and the Web
server, and a program that can be executed. This program is often a Perl script or
a program written in C and is often stored in the cgi-bin subdirectory on a Web
server.
Teaching
Stress that CGI scripts can raise security concerns on a Web server. A CGI script
Quick Quiz 3
1. You can create a Web page using ____________________ (HTML).
2. HTML is a format for creating documents with embedded codes known as
____________________.
3. The name of the computer at the loopback address is ____________________.
4. Perl is the most commonly used language for ____________________ (CGI)
programming.
Class Discussion Topics
2. Do any of your students have previous experience using PHP to create dynamic Web
pages? If so, ask them to compare PHP programming with Perl programming.
page-pfa
A Guide to Unix Using Linux, Fourth Edition 9-10
Additional Projects
1. In addition to the functionality discussed in this chapter, what other Perl features are
interesting and useful? Ask your students to compile a list of at least 10 features of the
2. What other programming languages are typically used for CGI programming? Ask your
Additional Resources
Key Terms
array A variable that stores an ordered list of scalar values that is accessed with
numeric subscripts, starting at zero.
page-pfb
A Guide to Unix Using Linux, Fourth Edition 9-11
diamond operator (<>) The operator used in Perl to access data from an open file.
Each time the diamond operator is used, it returns the next line from the file.
filehandle An input/output connection between a Perl program and the operating
loopback A feature that helps you experiment with and test HTML documents, or
Web pages, using a UNIX or Linux system. To use localhost, you need not be
connected to the Internet. Located on your PC, localhost also accesses your PC’s
internal network. Use localhost to ensure that networking is properly configured.
control statement, such as the sub statement in Perl, and a unique name that often
reflects its purpose.
tags The code embedded in a document or Web page created with Hypertext Markup
Language (HTML). When the document is viewed with a Web browser, such as Firefox
or Internet Explorer, the tags give the document special properties, such as foreground
page-pfc
A Guide to Unix Using Linux, Fourth Edition 9-12
Technical Notes for Hands-On Projects
The following projects should be completed using the command line (such as from a terminal
window), the Bash shell, and the students’ accounts and home directories, unless otherwise
specified. A text editor is needed to create the scripts and HTML files. Additional project
requirements are listed below.
Hands-On Project 9-7: Students need access to a computer that is running Fedora, Red Hat
Enterprise Linux, SUSE with the GNOME desktop, or Knoppix with the KDE desktop. The
Firefox Web browser should also be installed.

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.