Title: Chapter%20Nine
1Chapter Nine
2Lesson A
3Objectives
- Understand the basics of the Perl language
- Identify and use data types in Perl scripts
- Understand the difference between the Awk program
and Perl programming
4Objectives
- Create simple Perl scripts with variables and
logic structures - Create simple Perl scripts to read and sort data
files
5Introduction to Perl
Perl contains a features found in other languages
it is very similar to the C and also contains
features found in Awk and shell programs
6Introduction to Perl
Perl can be directed to read its input from the
keyboard
7Introduction to Perl
8Introduction to Perl
9Identifying Data Types
- Data may be represented in Perl in a variety of
ways - Variables and constants
- Scalars
- Numbers
- Strings
- Arrays
- Hashes
10Identifying Data Types
- Variables are symbolic names that represent
values stored in memory - The value of a variable can change while the
program runs constants do not change - Scalars are simple variables that hold a number
or a string - Scalar variable names begin with a dollar sign ()
11Identifying Data Types
- Numbers are stored as either signed integers, or
as double-precision floating-point values - Numeric literals can be either integers or
floating-point values - Perl uses added convention with numeric literals
to improve legibility the underscore character
(_)
12Identifying Data Types
- Strings are sequences of any types of characters
- Strings are often used for logical analysis,
sorts, or searches - String literals are usually delimited by either
single () or double quotes ()
13Identifying Data Types
14Identifying Data Types
15Identifying Data Types
The use of special codes determined the output of
this Perl script
16Identifying Data Types
- Arrays are variables that store an ordered list
of scalar values that are accessed with numeric
subscripts - An at sign (_at_) precedes the name of an array when
assigning it values - Use the dollar sign () when processing the
individual elements of an array
17Identifying Data Types
- Arrays are variables that represent a set of
key/value pairs - A percent sign () precedes the name of a hash
variable when assigning it a value - Use the dollar sign () to refer to a single
element of a hash
18Perl versus the Awk Program
The Awk program uses fewer lines of code to
resolve pattern-matching extractions than does
Perl
19How Perl Accesses Disk Files
Perl uses filehandles to reference files, as
shown in this figure
20Using Perl to Sort
You can sort words in a Perl program into
alphabetical order using the sort function
21Using Perl to Sort
Perl can access a file by passing the filename on
the command line
22Using Perl to Sort
You can sort numeric fields in a Perl program by
using a sort subroutine
23Lesson B
- Creating an Interactive Web Page
24Objectives
- Set up an HTML Web page
- Use Perl and CGI scripts to make your web pages
interactive - Use X Window and Netscape to retrieve Web pages
25Setting Up a Web Page
- Web pages can be created using HTML (Hypertext
markup Language) - HTML is a format for creating documents with
embedded codes known as tags and when the
document is viewed in a Web browser, the tags
give the document special properties - After using HTML to create a Web page, the page
is published on a Web server, this allows others
to access the document via the Internet
26Creating a Web Page
- HTML documents are created by typing its text and
the desired embedded tags - There are two parts to the HTML code
- The head contains the title, which appears on the
top bar of the browser window - The body defines what appears within the browser
window
27Creating Web Pages
An HTML document viewed in Netscape Navigator
28(No Transcript)
29CGI Overview
- CGI (Common Gateway Interface) is a protocol, or
set of rules, governing how browsers and servers
communicate - Scripts that send or receive information from a
server need to follow the CGI protocol - Perl is the most commonly used language for CGI
programming - Perl scripts are written to get, process, and
return information through Web pages
30(No Transcript)
31(No Transcript)
32(No Transcript)
33(No Transcript)
34(No Transcript)
35(No Transcript)
36Chapter Summary
- Perl is used as a powerful text-manipulation tool
similar to the Awk program - Perl is written in scripts that are translated
and executed by the Perl program - The Perl programmer has to write process-handling
instructions for data items to prevent
misidentification of data types and subsequent
processing errors - Perl has three basic data types scalars, arrays,
and hashes
37Chapter Summary
- A list is an ordered group of simple variables or
literals, separated by commas - Anything besides a textual sort must be handled
with a sort subroutine - An HTML document contains two parts a head and a
body - CGI is a protocol or set of rules governing how
browsers and servers communicate - To run your Web pages, you need to be in X Window
and have access to a Web browser