xix

Conventions

There is nothing sacred about convention:
there is nothing sacred about primitive passions or whims;
but the fact that a convention exists
indicates that a way of living has been devised
capable of maintaining itself.

- George Santayana, Persons and Places: The Middle Span

Computer programming languages are not the only means we have of encod-
ing information. To aid us in our explanations, we use the following conven-
tions throughout this book:

Typography

We use different fonts and type faces to convey information about the items
we are discussing:

Boldfont is used the first time a keywordor important term is used, or
when we wish to emphasize a term that you should recognize. Many of
the words you find in bold can also be found in the Index.

Italicfont is used for chapter titles, section names, and titles of recom-
mended reference works. It may also be used when we want to empha-
size a point. If you see something in italic font, pay attention.

Genevafont is used for "Macintosh computer voice". This includes much
of what you might see on your screen, such as the names of files and
folders, window titles, dialog box items, and menus. You may see
bold
Geneva
used if we are referring to something important, such as a menu
item you should remember.

Fixed widthfont is used for "Perl computer voice". When we ask you
to type some code on the keyboard, or show you a response that Perl


IMAGE imgs/030.Conventions01.gif

provides, we'll use a fixed width font such as Courier. Fixed width
font is also used for "MPW voice".

Terminology

If you are new to programming languages, you may find that some of our
terminology is new as well.

Scripts and Other Programs

We will refer throughout the book to the terms scriptand program. Pro-
grams are sets of executable code which tells the computer to do something.
A script is a type of program, usually interpreted, as compared to a binary
or compiledprogram. Scripts are often shorter, or perhaps simpler than
compiled programs; however, the distinction between scripts and other
types of programs is somewhat arbitrary. For now, consider that all scripts
are programs, but not all programs are scripts.

Characters

The following are new names for some familiar characters:

Quotation marks: ", ', and `

You may be more familiar with these as "quotes", 'apostrophes', and
`
what are those?`. We call them "double quotes", 'single quotes', and
`backquotes`. Occasionally, you will see references to the single quote
as a 'forward quote', to further distinguish it from the also single but
back-angled backquote.
1Colloquially, quote marks may be referred to
as tick marks or ticks.

Slash marks: / and \

The slash, /, may be familiar to you from other contexts. You may not be
as familiar with the backslash, \. Both are used throughout Perl. The
backslash is sometimes referred to as the escape character.

IMAGE imgs/030.Conventions02.gif

1Some, but not all, fonts show this quote as "leaning forward", ´.


IMAGE imgs/030.Conventions03.gif

Brackets and Braces: [], {}, <>

Technically, these characters are all termed brackets, specifically,
[square brackets], {curly brackets}, and <angle brackets>.
2A more spe-
cific and less verbose name for the curly brackets is braces. Left and
right angle brackets may be referred to separately in certain contexts as
less thanand greater thansigns or as left arrowand right arrow.

Personal Pronouns (he, she, or it?)

Throughout this book, we occasionally refer to the reader, or to the MacPerl
user, in the third person. When we do so, we use the word "he" in its tradi-
tional English grammatical sense as a gender-neutral singular pronoun. We
considered several possible "politically correct" alternatives, but settled on
traditional grammar as the form which best met our personal tastes. If you
prefer some other pronoun, feel free to substitute it in your mind as you read.

Style

Indentation

Computer programs in general, and Perl programs in particular, tend to
have a "block structure" which can (and should!) be emphasized by
indentation. Here, for instance, is some example code without indentation:

while (...) {
if (...) {
...
}
}

Here is the same code, indented by two spaces per level (the standard
followed in this book and preferred by some programmers):

while (...) {
if (...) {
...
}
}

IMAGE imgs/030.Conventions02.gif

2Parentheses, (), are sometimes called"round brackets", but you are unlikely to find
this usage in this book.


IMAGE imgs/030.Conventions05.gif

Here is the same code, indented by four spaces per level (the standard
recommended by Larry Wall and followed by many Perl programmers):

while (...) {
if (...) {
...
}
}

Our choice of a two-space indentation has more to do with the constraints of
book publishing than with any preference on our part. We use four spaces in
our own coding, but acknowledge that the two-space style is perfectly read-
able, if a bit cramped for our taste.

Neither of us, by the way, likes the "eight-space" indentation style. It
strikes us as hard to read and also uses up a lot of valuable space on each
line. On the other hand, TMTOWTDI (the Perl motto: There's More Than
One Way To Do It). The important thing, in any case, is consistency!

Punctuation

In computer programming, precision is very important. Precise syntax is crit-
ical to ensure that the computer does what the programmer expected. Au-
thors who program computers frequently require similar precision in their
English prose.

Quoted punctuation is a particular example of this. In Perl, there is a world
of difference between the command

print 'hello';

and the command

print 'hello;'

In writing this book, we subscribe to the convention that punctuation is
placed within the closing quote marks only if the punctuation itself is part
of the quoted material.
3

Parentheses

Many computer programming languages are quite strict about syntax rules,
such as using parentheses to enclose the parameters of function calls (and

IMAGE imgs/030.Conventions02.gif

3Doubting readers are referred to Webster's Standard American Style Manual,
Merriam-Webster, Inc.


IMAGE imgs/030.Conventions07.gif

other places).4Perl, however, takes a more liberal approach. Parentheses
are generally neither required nor forbidden - as the programmer, it's often
your call. Parentheses can be used to improve the clarity of the code. At
other times, they may just be a nuisance.

For this book, we've taken the approach that parentheses are more helpful
than not, so you will see a lot of parentheses in our examples. As you become
familiar with Perl, you can decide when to omit parentheses from your code.

Note:There are certain times (e.g., when creating lists or in certain
control flow statements) when parentheses may be required to make the
expression unambiguous. If you have been omitting parentheses and you
get a seemingly inexplicable syntax error, try adding parentheses to see
if that solves the problem.

One common place where parentheses are frequently left out is the print
statement. As you saw above, we wrote

print 'hello';

We could just as easily have written

print('hello');

Neither approach is wrong, but the unparenthesized version is somewhat
more common.

Our goal for this book is to teach you Perl. Our secondary goal is to teach
you how to write clear, maintainable, easy to understand code. Throughout
the book, we will make recommendations for what we regard as proper syn-
tax, and we'll usually take a fairly conservative approach. Whether you
decide to take our advice is your decision. The important thing is that your
programs work and (preferably) that other people can understand them!

Footnotes

Throughout the book, we have used footnotes to set off interesting5bits of
information which are related to, but not required by, the main text. We use
footnotes to point out some of the more esoteric aspects of Perl, to put things

IMAGE imgs/030.Conventions02.gif

4If you don't know what a function is, don't worry. We'll explain in the next few
chapters.

5At least, we think they are interesting!


IMAGE imgs/030.Conventions09.gif

into historical context, to make comparisons to other languages, or just to
make a side comment.

Don't worry if the information presented in the footnotes seems advanced or
even a bit strange. That's why we've set it off in a footnote!

URLs

We have omitted the leading "http://" from most of the World Wide
Web URLs (Uniform Resource Locators) listed in the book. If a site needs to
be accessed by some other means (e.g., FTP), we will say so explicitly.

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