(ebook) - O'Reilly - Advanced Perl Programming.pdf

(5210 KB) Pobierz
Advanced Perl Programming
Advanced Perl Programming
16408826.024.png 16408826.025.png 16408826.026.png 16408826.027.png 16408826.001.png 16408826.002.png 16408826.003.png 16408826.004.png 16408826.005.png 16408826.006.png 16408826.007.png 16408826.008.png 16408826.009.png 16408826.010.png 16408826.011.png 16408826.012.png 16408826.013.png 16408826.014.png 16408826.015.png 16408826.016.png
Copyright © 1999 O'Reilly & Associates . All Rights Reserved.
16408826.020.png
Preface
Next: Why
Perl?
Preface
Errors, like straws, upon the surface flow;
He who would search for pearls must dive below.
- John Dryden, All for Love, Prologue
This book has two goals: to make you a Perl expert, and, at a broader level, to supplement your current
arsenal of techniques and tools for crafting applications. It covers advanced features of the Perl language,
teaches you how the perl interpreter works, and presents areas of modern computing technology such as
networking, user interfaces, persistence, and code generation.
You will not merely dabble with language syntax or the APIs of different modules as you read this book.
You will spend just as much time dealing with real-world issues such as avoiding deadlocks during
remote procedure calls and switching smoothly between data storage using a flat file or a database.
Along the way, you'll become comfortable with such Perl techniques as run-time evaluation, nested data
structures, objects, and closures.
This book expects you to know the essentials of Perl - a minimal subset, actually; you must be
conversant with the basic data types (scalars, arrays, and hashes), regular expressions, subroutines, basic
control structures ( if , while , unless , for , foreach ), file I/O, and standard variables such as
@ARGV and $_. Should this not be the case, I recommend Randal Schwartz and Tom Christiansen's
excellent tutorial, Learning Perl , Second Edition.
The book - in particular, this preface - substantiates two convictions of mine.
16408826.021.png 16408826.022.png 16408826.023.png
The first is that a two-language approach is most appropriate for tackling typical large-application
projects: a scripting language (such as Perl, Visual Basic, Python, or Tcl) in conjunction with a systems
programming language (C, C++, Java). A scripting language has weak compile-time type checking, has
high-level data structures (for instance, Perl's hash table is a fundamental type; C has no such thing), and
does not typically have a separate compilation-linking phase. A systems programming language is
typically closer to the operating system, has fine-grained data types (C has short, int, long, unsigned int,
float, double, and so on, whereas Perl has a scalar data type), and is typically faster than interpreted
languages. Perl spans the language spectrum to a considerable degree: It performs extremely well as a
scripting language, yet gives you low-level access to operating system API, is much faster than Java (as
this book goes to press), and can optionally be compiled.
The distinction between scripting and systems programming languages is a contentious one, but it has
served me well in practice. This point will be underscored in the last three chapters of the book (on
extending Perl, embedding Perl, and Perl internals).
I believe that neither type of language is properly equipped to handle sophisticated application projects
satisfactorily on its own, and I hope to make the case for Perl and C/C++ as the two-language
combination mentioned earlier. Of course, it would be most gratifying, or totally tubular , as the local
kids are wont to say, if the design patterns and lessons learned in this book help you even if you were to
choose other languages.
The second conviction of mine is that to deploy effective applications, it is not enough just to know the
language syntax well. You must know, in addition, the internals of the language's environment, and you
must have a solid command of technology areas such as networking, user interfaces, databases, and so
forth (specially issues that transcend language-specific libraries).
Let's look at these two points in greater detail.
The Case for Scripting
I started my professional life building entire applications in assembler, on occasion worrying about trying
to save 100 bytes of space and optimizing away that one extra instruction. C and PL/M changed my
world view. I found myself getting a chance to reflect on the application as a whole, on the life-cycle of
the project, and on how it was being used by the end-user. Still, where efficiency was paramount, as was
the case for interrupt service routines, I continued with assembler. (Looking back, I suspect that the
PL/M compiler could generate far better assembly code than I, but my vanity would have prevented such
an admission.)
My applications' requirements continued to increase in complexity; in addition to dealing with graphical
user interfaces, transactions, security, network transparency, and heterogeneous platforms, I began to get
involved in designing software architectures for problems such as aircraft scheduling and network
management. My own efficiency had become a much more limiting factor than that of the applications.
While object orientation was making me more effective at the design level, the implementation language,
C++, and the libraries and tools available weren't helping me raise my level of programming. I was still
dealing with low-level issues such as constructing frameworks for dynamic arrays, meta-data, text
manipulation, and memory management. Unfortunately, environments such as Eiffel, Smalltalk, and the
Zgłoś jeśli naruszono regulamin