
Reviewed by
Donald
Bryson
By Eric F. Johnson
351 pages.
nine pages of contents;
Appendix;
seven pages of index, CD-ROM
ISBN 1-55851-483-X, paperback $34.95
Available at a discount from Amazon.com on
this page
Technical Level: computing -- professional, subject -- newbie
to experienced
Information: concepts: good; practice: exceptional
Readability: textbook: good; reference: passable
Summary:
An introduction to writing portable Perl
scripts in both Unix and Windows NT. The book explains potential
problems and solutions encountered in a multi-platform Perl
development project. While specifically addressing Unix and NT,
the book touches on the problems encountered when porting scripts
to MS-DOS and Windows 95.
Publisher:
M&T Books, A Division of MIS:Press, Inc.
A Subsidiary of Henry Holt and Company, Inc.
115 West 18th Street New York, New York 10011
http://www.mandt.com
Cross-platform development is a war. Trenches connect each
platform across a bleak no-mans land. Advice from a seasoned
veteran can save you hours o
f frustration. Eric Johnson is such
a veteran. He has been in the trenches and speaks with
authority. This book is full of practical gems that you can use
in cross-platform development in any language.
For example: How do you strip the end-of-line from user input?
Some scripts use the Perl
chop
command. Johnson
warns against
chop
and advises the reader to use
chomp
instead. Why? Because
chop
always removes the last character from a line, whereas
chomp
only removes the line ending characters listed
by the Perl
$/
or
$INPUT_RECORD_SEPARATOR
scalar variable. Although
chop
works fine on a Unix system, which terminates
the line with a single line-feed character, it will fail on MS-DOS
and Windows systems, which use a two-character (carriage return,
line feed line) termination sequence. By default,
chomp
removes the single line-feed character in Unix
and the two character termination
sequence in Windows NT.
How can your Perl script determine the current host operating
system? It could check for unique OS environmental variables.
TERM
would be the logical one to check. Why?
TERM
is required for all programs using the termcap
or terminfo libraries on a Unix system and the termcap, terminfo
libraries are virtually exclusive to Unix. However, Johnson
correctly warns against it. Some MS-DOS applications will only
execute when TERM is defined. For example, all programs in both
the Unix and MS-DOS environments linked with d-tree(r) from
Faircom require TERM to be defined.
It's the little things like line terminators and unlikely
environmental variables that will cause you the most grief when
programming for more than one operating system. A veteran like
Johnson has stumbled over those pebbles before.
The book is also a good introduction to Perl as a second
language (that is, not your first programming language). However,
buy a different bo
ok if you are new to programming. Johnson
explains key concepts by direct comparison and contrast. For
instance, he compares the Perl regular expressions to regular
expressions recognized by the Unix
egrep(1)
command.
And, instead of providing a lengthy discussion of what
constitutes a code block, he simply states that, unlike C, curly
braces generally delimit a code block. This is an efficient way
of teaching another programming language to an experienced
programmer, but cryptic for the novice.
Johnson is aware that readers are naturally stronger in a
particular operating system. He takes time to explain concepts
unique to Unix or Windows. For example, he explains Unix white
space for the Windows reader and the Windows registry for the
Unix reader.
The book is well organized. Each chapter starts with a brief
overview. The body of each chapter contains numerous code
examples, easy to follow icons, and clear text. Each chapter
concludes wit
h a summary and a list of the new commands presented
in that chapter.
While worth the time and money, the book does have one
weakness. Johnson loses his focus toward the end of the book.
In the introduction he writes, ``What I've tried to do is focus
on the most important and useful constructs in Perl, especially
constructs that work on a number of platforms'', but then spends
the last 10% of the book discussing Perl/Tk, which isn't even
available for Windows. However, as Johnson points out, Tcl and
Tk have been ported to Windows so there is a good chance that
Perl/Tk will be ported to Windows as well.
Table of Contents:
Introduction
- Using Perl for Cross-Platform Development
- When to Use Perl
- Perl Versions
- Acquiring Perl
- Learning Perl
- Contacting the Author
Section I: Perl
- Chapter 1: Beginning with Perl
- A First Perl Script
- Getting Input in Perl S
cripts
- How Perl Runs Programs
- Finding Out More about Perl's Commands
- Making Your Scripts into Commands
- Summary
- Chapter 2: Perl Basics
- The Perl You Need to Know
- Controlling Your Perl Scripts
- Math
- Operations on Text
- Variables and Arrays
- Command-Line Arguments
- Subroutines
- Summary
- Chapter 3: Working with Files
- Files
- Directories
- Symbolic Links
- Packages
- Summary
- Chapter 4: Transforming Data: Pattern Matching and Substitution
- Searching for Data in Text
- Using Patterns with Substitutions
- Transforming Data with tr
- Summary
- Chapter 5: Formatting Reports
- Reports
- Formats
- Other Means to Control Data Output
- Putting the Date into Your Reports
- Databases and Perl
- Connecting Other D
atabases to Perl
- Summary
- Chapter 6: Launching Applications
- Launching External Programs
- Detecting Whether Your Script is Running on Windows or Unix
- Controlling Processes
- Pipes
- Alarm Clocks and Sleeping
- Using eval to Control the Command Line
- Summary
- Chapter 7: Perl Packages and Modules
- Packages
- Modules
- Extensions
- Common Packages, Modules, and Extensions
- Inside a Package
- References and Objects
- Summary
Section II: Advanced Perl
- Chapter 8: Perl for System Administrators
- Working with Users
- Host Names
- Windows System Information
- Other Administration Tasks
- Summary
- Chapter 9: Perl for Web Pages
- How Web Pages Work
- The Common Gateway Interface
- Using Perl for CGI Scripts
- Using the C
GI Module
- Data-Entry Forms in Web Pages
- Passing Data on the Command Line
- The Self-Maintaining Web Page
- Summary
- Chapter 10: Perl for Cross-Platform Development
- Automating the Software Development Process
- Summary
- Chapter 11: Perl for Client-Server
- Networking with Perl
- Socket-Based Communications
- Perl Modules for Networking
- Summary
- Chapter 12: Graphical Interfaces with Perl and Tk
- Adding Graphical Interfaces to Your Perl Scripts
- Installing Perl/Tk
- Scripting with Perl/Tk
- Summary
Appendixes:
- Learning More
- Books
- Other Sources of Information
(
Return to the top of this review.
)
|