v

Contents

Contents

v

Dedications

xiii

Acknowledgements
First And Foremost ...
Technical Assistance ...
And Review ...
Ancillary Materials...
Publicity and Documentation ...
Last But Not Least ...

xv
xv
xvi
xvi
xvii
xviii
xviii

Conventions
Typography
Terminology
Personal Pronouns (he, she, or it?)
Style
Footnotes
URLs

xix
xix
xx
xxi
xxi
xxiii
xxiv

MacPerl Escapes From The Laboratory

xxv

Part I - Preparation

0

Introduction
What Is Perl?
What About AppleScript?
What About Other Languages?
Scope
Audiences
Roadmap
Advice
Why Chapter 0?

3
3
5
6
7
8
11
12
12

1

A Peek Into Programming
Cooking Up A Program
Program Structure

13
14
15


IMAGE imgs/015.Contents01.gif

Error Checking
The Programming Process
Testing: 1, 2, 3, ...

17
18
20

2

A Dip Into Data
Bits And Bytes
Quantifying Data Storage
Values, Variables, And Calculation
Data Structures

21
22
23
24
25

3

A Step Into Syntax
Syntax, Meaning, And Truth
Expressions, Statements, And Blocks
Data Structures
Control Flow
Functions And Methods
Parenthetical Remarks
Combinatorial Complexity

27
28
30
31
33
34
36
37

4

Installation And Overview
MacPerl Flavors
System Requirements
Installing The Standalone Application
Examine The Results
A Walk Through The Menus
On-line Help - Installing Internet Config
A New Menu
Running A Script
Check The Preferences

39
39
40
41
43
45
48
51
51
53

Part II - Learning The Language

5

Building Blocks
Literals - Numbers And Strings
Variables
Case - A Sensitive Issue
Quoting
Operators
Precedence

59
61
61
62
63
64
68


IMAGE imgs/015.Contents02.gif

Expressions
Statements
Commands: Operators, Functions, And More
Control Flow

69
70
70
73

6

Stacking The Blocks
Input And Output (I/O)
More Commands?
Pattern Matching
Breaking Data Apart
An Array Of Possibilities
Multiple Dimensions
Context

77
77
79
82
86
88
89
93
93

7

Filing The Edges
Filehandles
Reading Input
Error Handling
Pathnames
Writing Output
Redirecting Standard I/O
Working With Folders (Directories)
Working With Aliases

95
95
98
99
100
103
107
109
110

8

Curious Constructions
Subroutines
The Standard Perl Library
Adding Libraries - The CPAN
Mac-specific Functions
Droplets, Runtime Versions, And CGI scripts
Program Arguments: @ARGV
References
Filename Globbing
Passing Filehandles

111
111
117
119
120
121
123
124
126
127

9

Odd Corners
$_
use English
MacPerl Oddities - Portability Issues

129
130
130
131


IMAGE imgs/015.Contents03.gif

To Parenthesize Or Not To Parenthesize
Taking Shortcuts
Quoting
Extended Regular Expressions
A Word Of Warning
Grab Bag

134
135
138
140
141
143

10

Help!
Start With A Good Editor
Good Habits Cost No More
Debugging Techniques
RTFM
Recommended Reading
The Perl Community

145
145
146
148
154
155
155

Part III - Advanced Topics

11

Extensibility And Re-use
Packages, Modules, Extensions (Oh My!)
Understanding Modules
Getting Modules
Installing Modules
use-ing Modules
Object-Oriented Programming

159
159
161
163
164
168
169

12

The MacPerl Package
Volumes, Paths, And File Specifications
File Information
Answer, Ask, Pick
Quit
$Version
LoadExternals
DoAppleScript
Reply

171
172
173
174
177
177
177
178
178

13

The Toolbox Modules
Using The Toolbox Modules
Mac::AppleEvents, Mac::OSA
Mac::Files

179
181
181
182


IMAGE imgs/015.Contents04.gif

Mac::StandardFile
Mac::MoreFiles
Mac::Processes
Mac::Gestalt
Mac::Types
Mac::Memory
Mac::Resources
Mac::InternetConfig

184
188
189
191
192
193
194
195

14

GUI Toolbox Modules
Windows
Window Definitions
Drawing And Text
Events
Controls
Menus
Dialogs
Roll Your Own

197
198
200
204
208
209
212
214
217

15

Data Storage
Database Basics
Delimited Text
DBM
Database Servers
Data Formats

219
220
222
224
226
227

16

CGI Scripting
Web Servers
The CGI Script Extension
CGI vs. ACGI
Taint Checking
Environment Variables
CGI.pm

229
229
231
233
234
236
236

17

Network Programming
Sockets
libnet
LWP
AppleTalk
Debugging

239
240
242
244
244
246


IMAGE imgs/015.Contents05.gif

18

AppleScript, Etc.
AppleScript
Other OSA Languages
Apple Events
An Apple Event Example

247
248
251
252
253

Part IV - Reference

19

Operators
Precedence And Associativity
Arithmetic Operators
String Operators
Assignment Operators
Comparison Operators
Logical Operators
Bit-Shift Operators
Binding (Matching) Operators
Reference / Dereference Operators
Range Operators
Comma Operator
Conditional Operator
File Test Operators
Quoting
Escape Sequences
Regular Expressions
Switches

259
259
262
262
263
263
264
265
265
265
266
266
267
267
271
272
273
273

20

Reserved Words
Alphabetical List
Categories
Synopses

277
279
280
283

21

Special Variables
Data Structures
Format
Input/Output
Operating Environment
Package Management
Perl Interpreter

303
304
304
305
307
308
308


IMAGE imgs/015.Contents06.gif

Process Management
Regular Expression

309
310

22

MPW Perl
What Is MPW?
Using Perl With MPW
Install The MPW Tool
Examine The Folder
Complete The Installation
Try Out The MPW Tool
Special Features Of The MPW Tool

311
311
313
314
316
317
318
320

23

Building MacPerl And Extensions
What You Need
Setting It Up
Building MacPerl
Building Extensions

327
328
328
330
331

Part V - Resources

24

Books, Etc.
General
Languages
Programming
Networks, Etc.

337
338
339
343
345

25

Contact Information

351

Who We Are ...

355

Notes

357

Index

359

Copyright © 1997-1998 by Prime Time Freeware. All Rights Reserved.