Special Edition
Using Perl
for
Web Programming
David Harlan
, et al.
CONTENTS
Chapter
1
Perl Overview
Perl
Origins
Borrowings
Cost and Licensing
Distribution
Perl Programs
Invocation
Command-Line Arguments
Program Layout
Data Types
Scalars
Arrays
Associative Arrays
File Handles
Special Variables
Environment Variables
Program Arguments
Current Line
System Error Messages
Flow Control
Logical Operators
Conditional Expressions
Compound Statements
Loops
Labels
Subroutines
Variable Scope
Patterns
Regular Expressions
Matching
Substitution
From Here
Chapter
2
Introduction to CGI
Justifying the Use of CGI
Reasons for Using Perl
How to Make Perl Do CGI
Understanding CGI
Calling a Script from a Form
Getting Information to the Script
Processing
QUERY_STRING
into Useful Chunks
Using Regular Expressions
tr///
and
s///
Printing the Page
Creating a Script on Your Web Server
Calling a CGI Script Directly
Limiting Data-File Size
Using the Location Header
Using CGI in Server-Side Includes
From Here
Chapter
3
Advanced Form Processing and Data Storage
Using the
POST
Method
Comparing
GET
and
POST
Processing the Information from a
POST
-Method Form
Making Your Perl Code Modular
Defining and Calling Subroutines
Using Variable Aliases
Using DBM Files for Data Storage
Opening a DBM File
Assigning Values to a DBM File
Initializing a DBM File
Adding Data to the DBM File
Using Complex Forms and Storing Related Data
Processing the Form Data and Checking the Password
Working Around the Limitations of DBM Files
From Here
Chapter
4
Advanced Page Output
Parsing the DBM File and Printing Pages
Printing a Standard Page
Printing User-Designed Pages
Returning Data to a Form for Further Revision
Filling in Text Fields and Selecting List Items
Saving and Editing User-Designed Pages
From Here
Chapter
5
Searching
Searching the Full Text of Your Site
Scanning Directories Using a Recursive Subroutine
Using Recursive Subroutines
Processing the Files in Each Directory
Using an Index Search
Indexing Your Web Site into a DBM File
Performing a Search Using the Index File
Printing the Resulting Pages
Returning Pages from the Nonindex Search
Returning Pages from the Index Search
From Here
Chapter
6
Using Dynamic Pages
Generating HTML Pages
Understanding the CGI Environment and HTML Generation
CGI Environment Variables Using the
GET
Method
CGI Environment Variables Using the
POST
Method
Referring the User to Browser-Specific Web Pages
Using Client Pull with Perl
Using Server Push with Perl
From Here
Chapter
7
Dynamic and Interactive HTML Content in Perl and CGI
Creating User-Specific Pages
Allowing the User to Shop for Options
Building an HTML Document Based on Options
Using Server-Side Includes
Understanding the SSI Commands
Setting up an Environment for Server-Side Includes
Understanding the Commands
Understanding Shopping Carts
Shopping Cart Using Hidden Fields
Shopping Cart Using HTTP Cookies
From Here
Chapter
8
Understanding Basic User Authentication
Basic User Authentication
Processes and User IDs
CGI Program Execution
Access Control
User Identification
User Authentication on the Apache Server
Access Restrictions
Apache Configuration Files
Configuration Directives
User Administration
Adding Users
Deleting Users
Changing Passwords
Adding Users to Groups
Deleting Users from Groups
From Here
Chapter
9
Understanding CGI Security
Understanding the Security Issues
Tracing the Chain of Command
Reading Files
Writing to Files
Storing Variables
Losing the Data
Managing Sessions
The Nature of a Session
The Wrapper
Generic Substitutions
Flow Control
Designing the Sample Application
Program Flow
Data Issues
Implementing the Sample Application
Getting Started: The Main Routine
Getting the CGI Values
Reading the Product Data
Invoking a Specific Function
Parsing an HTML File
Initiating a Login
Logging In and Out
Logging In
Validating the User
Logging Out
Managing Session Data
Storing Session Data
Retrieving Session Data
Managing the Orders
Building an Order
Reviewing the Order
Placing the Order
Wrapping Up
From Here
Chapter
10
Site Administration
Working with Web Server Log Files
Generating HTML Output from a Log File
Reviewing the AccessWatch Log Analyzer
Understanding File Maintenance
Understanding Robots and the Robot-Exclusion Standard
Configuring Some Common Web Servers
O'Reilly's WebSite
NCSA httpd
Apache
Examining Some Other File- and Site-Administration Issues
From Here
Chapter
11
Database Interaction
Justifying Perl/Database Interaction
Examining the Database Options
DBI and DBD Database Access Modules for Perl 5
mSQL and mSQLPerl
Oracle RDBMS and Oraperl
Starting a New Message Thread
Listing Threads and Displaying the Contents of a Single Thread
Navigating Through Messages and Posting Replies
From Here
Chapter
12
Database Application Using CGI
Fundamental Design and Security Issues
Advantages and Disadvantages of a Web/RDBMS Interface
Limitations of HTTP in a Database Context
Security Issues
A Simple Working Example in Perl
Accessing a DBMS from Perl
Defining the Database Schema for the Working Example
Searching the Hotlist
Viewing the Detail Record
Submitting Data to the Hotlist
Generating SQL Code to Transfer Submitted Data
Perl Tools for Web/DBMS Work
WDB
Web/Genera
MiniSQL (mSQL) and W3-mSQL
DBI
ODBC Tools
Some Useful Hotlists
Problem-Solving
Debugging
Tuning Performance
The Future of Web/Database Interfaces
From Here...
Chapter
13
Special Variables
$<I<digit>>
$[
$ACCUMULATOR
$ARG
$ARGV
$BASETIME
$CHILD_ERROR
$DEBUGGING
$EFFECTIVE_GROUP_ID
$EFFECTIVE_USER_ID
$EVAL_ERROR
$EXECUTABLE_NAME
$FORMAT_FORMFEED
$FORMAT_LINES_LEFT
$FORMAT_LINES_PER_PAGE
$FORMAT_LINE_BREAK_CHARACTERS
$FORMAT_NAME
$FORMAT_PAGE_NUMBER
$FORMAT_TOP_NAME
$INPLACE_EDIT
$INPUT_LINE_NUMBER
$INPUT_RECORD_SEPARATOR
$LAST_PAREN_MATCH
$LIST_SEPARATOR
$MATCH
$MULTILINE_MATCHING
$OFMT
$OS_ERROR
$OUTPUT_AUTOFLUSH
$OUTPUT_FIELD_SEPARATOR
$OUTPUT_RECORD_SEPARATOR
$PERLDB
$PERL_VERSION
$POSTMATCH
$PREMATCH
$PROCESS_ID
$PROGRAM_NAME
$REAL_GROUP_ID
$REAL_USER_ID
$SUBSCRIPT_SEPARATOR
$SYSTEM_FD_MAX
$WARNING
%ENV<variable_name>
,
<variable_value>
%INC<file-name>
,
<file-load-status>
%SIG<signal-name>
,
<signal-value>
@ARGV
@INC
From Here...
Chapter
14
Operators
!
!=
!~
%
%=
&
&&
&&=
&=
*
**
**=
*=
+ (Unary)
+ (Binary)
++
+=
,
- (Unary)
- (Binary)
--
-=
->
.
..
.=
/
/=
<
<<
<<=
<=
<=>
=
==
=>
=~
>
>=
>>
>>=
?
LIST Operators (Leftward)
LIST Operators (Rightward)
NAMED Unary Operators
TERMs
"
^
^=
and
cmp
eq
ge
gt
le
lt
ne
not
or
x
x=
xor
|
|=
||
||=
~
From Here...
Chapter
15
Function List
-A
Compliance
Syntax
Definition
Example
-B
Compliance
Syntax
Definition
Example
-b
Compliance
Syntax
Definition
Example
-C
Compliance
Syntax
Definition
Example
-c
Compliance
Syntax
Definition
Example
-d
Compliance
Syntax
Definition
Example
-e
Compliance
Syntax
Definition
Example
-f
Compliance
Syntax
Definition
Example
-g
Compliance
Syntax
Definition
Example
-k
Compliance
Syntax
Definition
Example
-l
Compliance
Syntax
Definition
Example
-M
Compliance
Syntax
Definition
Example
-O
Compliance
Syntax
Definition
Example
-o
Compliance
Syntax
Definition
Example
-p
Compliance
Syntax
Definition
Example
-R
Compliance
Syntax
Definition
Example
-r
Compliance
Syntax
Definition
Example
-S
Compliance
Syntax
Definition
Example
-s
Compliance
Syntax
Definition
Example
-T
Compliance
Syntax
Definition
Example
-t
Compliance
Syntax
Definition
Example
-u
Compliance
Syntax
Definition
Example
-W
Compliance
Syntax
Definition
Example
-w
Compliance
Syntax
Definition
Example
-X
Compliance
Syntax
Definition
Example
-x
Compliance
Syntax
Definition
Example
-z
Compliance
Syntax
Definition
Example
abs
Compliance
Syntax
Definition
Example
accept
Compliance
Syntax
Definition
alarm
Compliance
Syntax
Definition
Example
atan2
Compliance
Syntax
Definition
Example
bind
Compliance
Syntax
Definition
binmode
Compliance
Syntax
Definition
Example
bless
Compliance
Syntax
Definition
Example
caller
Compliance
Syntax
Definition
Example
chdir
Compliance
Syntax
Definition
Example
chmod
Compliance
Syntax
Definition
Example
chomp
Compliance
Syntax
Definition
Example
chop
Compliance
Syntax
Definition
Example
chown
Compliance
Syntax
Definition
Example
chr
Compliance
Syntax
Definition
Example
chroot
Compliance
Syntax
Definition
Example
close
Compliance
Syntax
Definition
Example
closedir
Compliance
Syntax
Definition
Example
connect
Compliance
Syntax
Definition
continue
Compliance
Syntax
Definition
Example
cos
Compliance
Syntax
Definition
Example
crypt
Compliance
Syntax
Definition
Example
dbmclose
Compliance
Syntax
Definition
dbmopen
Compliance
Syntax
Definition
defined
Compliance
Syntax
Definition
Example
delete
Compliance
Syntax
Definition
Example
die
Compliance
Syntax
Definition
Example
do
Compliance
Syntax
Definition
Example
dump
Compliance
Syntax
Definition
each
Compliance
Syntax
Definition
Example
endgrent
Compliance
Syntax
Definition
Example
endhostent
Compliance
Syntax
Definition
Example
endnetent
Compliance
Syntax
Definition
Example
endprotoent
Compliance
Syntax
Definition
Example
endpwent
Compliance
Syntax
Definition
Example
endservent
Compliance
Syntax
Definition
Example
eof
Compliance
Syntax
Definition
Example
eval
Compliance
Syntax
Definition
Example
exec
Compliance
Syntax
Definition
Example
exists
Compliance
Syntax
Definition
Example
exit
Compliance
Syntax
Definition
Example
exp
Compliance
Syntax
Definition
Example
fcntl
Compliance
Syntax
Definition
fileno
Compliance
Syntax
Definition
Example
flock
Compliance
Syntax
Definition
fork
Compliance
Syntax
Definition
Example
format
Compliance
Syntax
Definition
Example
formline
Compliance
Syntax
Definition
Example
getc
Compliance
Syntax
Definition
Example
getgrent
Compliance
Syntax
Definition
Example
getgrgid
Compliance
Syntax
Definition
Example
getgrname
Compliance
Syntax
Definition
Example
gethostbyaddr
Compliance
Syntax
Definition
Example(Perl5 only)
gethostbyname
Compliance
Syntax
Definition
Example
gethostent
Compliance
Syntax
Definition
Example
getlogin
Compliance
Syntax
Definition
Example
getnetbyaddr
Compliance
Syntax
Definition
Example
getnetbyname
Compliance
Syntax
Definition
Example
getnetent
Compliance
Syntax
Definition
Example
getpeername
Compliance
Syntax
Definition
getpgrp
Compliance
Syntax
Definition
Example
getppid
Compliance
Syntax
Definition
Example
getpriority
Compliance
Syntax
Definition
Example
getprotobyname
Compliance
Syntax
Definition
Example
getprotobynumber
Compliance
Syntax
Definition
Example
getprotoent
Compliance
Syntax
Definition
Example
getpwent
Compliance
Syntax
Definition
Example
getpwnam
Compliance
Syntax
Definition
Example
getpwuid
Compliance
Syntax
Definition
Example
getservbyname
Compliance
Syntax
Definition
Example
getservbyport
Compliance
Syntax
Definition
Example
getservent
Compliance
Syntax
Definition
Example
getsockname
Compliance
Syntax
Definition
getsockopt
Compliance
Syntax
Definition
glob
Compliance
Syntax
Definition
Example
gmtime
Compliance
Syntax
Definition
Example
goto
Compliance
Syntax
Definition
Example
grep
Compliance
Syntax
Definition
Example
hex
Compliance
Syntax
Definition
Example
import
Compliance
Syntax
Definition
index
Compliance
Syntax
Definition
Example
int
Compliance
Syntax
Definition
Example
ioctl
Compliance
Syntax
Definition
join
Compliance
Syntax
Definition
Example
keys
Compliance
Syntax
Definition
Example
kill
Compliance
Syntax
Definition
last
Compliance
Syntax
Definition
Example
lc
Compliance
Syntax
Definition
Example
lcfirst
Compliance
Syntax
Definition
Example
length
Compliance
Syntax
Definition
Example
link
Compliance
Syntax
Definition
Example
listen
Compliance
Syntax
Definition
local
Compliance
Syntax
Definition
localtime
Compliance
Syntax
Definition
Example
log
Compliance
Syntax
Definition
Example
lstat
Compliance
Syntax
Definition
Example
m//
Compliance
Syntax
Definition
Example
map
Compliance
Syntax
Definition
Example
mkdir
Compliance
Syntax
Definition
Example
msgctl
Compliance
Syntax
Definition
msgget
Compliance
Syntax
Definition
msgrcv
Compliance
Syntax
Definition
msgsnd
Compliance
Syntax
Definition
my
Compliance
Syntax
Definition
next
Compliance
Syntax
Definition
Example
no
Compliance
Syntax
Definition
Example
oct
Compliance
Syntax
Definition
Example
open
Compliance