|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39
|
|
Chapter 4:
|
|
|
|
Installation And Overview
|
|
One doesn't discover new lands
without consenting to lose sight of the shore
for a very long time.
|
|
-André Gide, The Counterfeiters
|
|
This chapter describes the installation of MacPerl and provides a brief "get
acquainted" overview. If you already have a working copy of MacPerl on
your disk, you may want to skip this chapter. Or, you may wish to read the
sections on menus and preferences, in case you might see something new.
|
|
MacPerl Flavors
|
|
There are two flavors of MacPerl - the standalone application (app),
which works similarly to most other Macintosh programs, and the MPW
tool. The MPW tool is only useful if you also have a copy of MPW, Apple's
Macintosh Programmer's Workshop, installed. MPW is a complete Macin-
tosh programming environment, consisting of a shell(command line inter-
preter) and various tools. The MPW perltool may be more familiar to
users of Unix or DOS, as it is accessed from the command line.
|
|
Although MPW is somewhat more readily available than it once was, it is
not in widespread use except among Macintosh software developers. Thus,
we do not expect that many readers of this book will be MPW users. If you
do not plan to use MPW, you may wish to skip ahead to the next section,
System Requirements.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
If you plan to use Perl with MPW, be sure to follow the instructions below to
install the standalone app. The installation script for the MacPerl MPW
tool requires that the MacPerl application package be installed first!
|
|
The examples in this book were written (and tested) using the standalone
app. In most cases, this will make little difference. Occasionally, MPW
users may have to make slight adjustments to our examples in order to make
them work under MPW.
|
|
Complete instructions for installing the MacPerl MPW tool, as well as spe-
cial features pertaining to the tool, are described in Chapter 22 in Part IV
of this book. This book does not, however, provide detailed information
about using the MPW environment. If you are not already familiar with
MPW, we suggest that you familiarize yourself with MPW beforeyou
attempt to install or use the MacPerl MPW tool.
|
|
If you are familiar with MPW, but have never used Perl, we suggest that
you install only the standalone app at first, then work your way through
the tutorial material in Part II. After you have become comfortable with
Perl, you can install the MacPerl tool under MPW.
|
|
System Requirements
|
|
MacPerl requires that your Macintosh be running Mac OS System 7 or later.
Be sure you have at least 4 MB of memory available, more if you wish to run
complex scripts or work with large amounts of data.
|
|
MacPerl can be installed in any of several ways. The Easy Install option
installs an application most suited to your system: either PowerPC systems
(Power Macintosh, later Powerbooks, and Performa systems with 4-digit
model numbers (7500, 2300, 6400, ...)) or Motorola 68K-based Macintoshes
(the Mac II, early Powerbooks, the Centris or Quadra series, etc.). Alter-
natively, you may wish to install a "fat" version of MacPerl, which will
run on any Macintosh model. To do this, you will need to perform a "Cus-
tom" installation.
|
|
M68K processor-based Macintoshes
|
|
If you are installing MacPerl on a 68K-based Macintosh, however, the
default installation may not be sufficient for your needs. The standard, or
"small" 68K MacPerl has only a "minimal" set of modules linked in static-
ally; these modules provide functionality which has always been present
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
in previous releases of MacPerl. These modules are: DB_File, DynaLoad
er, Fcntl, IO, MacPerl, NDBM_File, Opcode, POSIX, and Socket.
|
|
Two alternative versions of the MacPerl application are also available for
68K Macintoshes. "Big MacPerl" (bigappl) has additionally linked in the
GD module and all Mac Toolbox modules. Dynamic 68K, or CFM68K (appl_
cfm68K), includes the same modules as the small version, but is also able to
load arbitrary modules dynamically.
|
|
Note: Some functionality in the Perl core modules, such as File::Copy, is
implemented via the Toolbox Modules. If you use a 68K Mac, make sure
that either CFM-68K MacPerl or BigMacPerl is installed.
|
|
If you plan to install the CFM68K MacPerl application, you must make sure
that your system supports it. You will need to have the following Mac OS
System Software installed:
|
|
-
AppleScript Lib version 1.2.2 or later
|
|
-
ObjectSupportLib version 1.2 or later
|
|
-
CFM-68K Runtime Enabler version 4.0 or later
|
|
This software should already be present on 68030- or 68040-based Macin-
tosh models running MacOS 7.6.1 or later. Under Mac OS 8.0 and later, do
notinstall CFM-68K Runtime Enabler or ObjectSupportLib; they are built-
in to the System file.
|
|
Installing The Standalone Application
|
|
If you have downloaded a recent copy of the MacPerl application from one
of the archive sites on the Internet, the file will most likely be compressed
and encoded, usually with StuffIt(from Aladdin Systems) and BinHex.
|
|
In this case, you will need to decode and uncompress the archive before con-
tinuing. StuffIt Expander, an expansion utility from Aladdin, is included on
the enclosed CD-ROM and is also freely available from many Macintosh
archive sites or from Aladdin Systems at www.aladdinsys.com.
|
|
If you are installing MacPerl from the included CD-ROM, you won't need to
uncompress or decode an archive. (We have supplied the MacPerl Installer
as a ready-to-run application.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Once you have unpacked the MacPerl Installer, life gets pretty easy. All
you need to do is launch the Installer application, review the instructions
for any important last-minute notes, select the installation location, and
click Install. The Installer will install everything you need to use MacPerl,
including examples, all libraries, documentation, and the "standard"
MacPerl application.
|
|
If you wish to install one of the alternative (Big or CFM68K) standalone
versions of MacPerl, or you wish to install the MacPerl MPW tool, be sure to
complete the standard installation first. The alternative distributions
contain only the alternative application (or tool) and a small number of
additional files.
|
|
You should install the distributions as suggested in the figure below, from
bottom to top. That is, if you wish to use the big MPW tool, you should first
install the standard application (appl), then the standard MPW tool dis-
tribution, then the bigtool distribution.
|
|
|
|
All distributions are available on the CD-ROM included with this book, or
can be downloaded from the MacPerl archive sites.
|
|
Steps to Install the MacPerl standalone app
|
|
-
Double-click the Installer application to start the installation. Be sure
to review the instructions in the initial screen for any important last-
minute notes. Print or save these notes, then click Continue.
|
|
-
If you wish to install a fat binary, be sure to select Custom Install from
the popup menu; otherwise, select Easy Installas shown. Choose the
volume and folder where you wish to install MacPerl, then click
Install.1
|
|
-
The Installer will install everything you need to use MacPerl.
|
|
|
|
1We have removed some blank space from this and other dialog images; don't worry if
the dialogs on your screen have substantially more white space than we show.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You can safely ignore most of the files and folders for now. There are, how-
ever, several items that you should recognize and understand, as they will
be useful to you shortly. Examine the contents of the MacPerl folder.
|
|
-
The MacPerl application has an icon of a camel and a pyramid.2This
is the actual double-clickable application which you will be running
when you use MacPerl.
|
|
-
The files README.MACand READMEcontain general information
about MacPerl and Perl, respectively. These files contain release notes,
information on known problems, special comments about the current
release, etc. Be sureto take a look at these README files.
|
|
-
The Perl Artistic License file contains information related to the
circumstances under which you are permitted to use Perl, give it away,
or sell software that is based on it. Be sure to read this file as well.
|
|
-
The Perl online documentation is stored in the pod folder (POD stands
for Plain Old Documentation). The POD files comprise your best user
|
|
|
|
2Due to trademark issues, this icon may change on future versions of MacPerl.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
manual. POD files are text and can be read with many applications,
including MacPerl itself. However, they will look better if you use a
program designed to read POD files, such as Shuck.
The Shuckappli-
cation is included with the MacPerl distribution; its icon resembles a
partially-shucked ear of corn.
|
|
-
The lib folder contains MacPerl libraries, additional functions, and
modules which you may include in your programs to give you additional
capabilities. We'll cover libraries and modules in a later chapter.
|
|
-
There are also a few files which contain information specific to Mac-
Perl itself (as opposed to Perl documentation in general). You should
read MacPerl.Frontend, MacPerl.Packages, and MacPerl.Spe-
cifics.
|
|
-
Many of the remaining folders contain examples of Perl code. Feel free
to peruse these at your leisure. We recommend, however, that you do
not move, remove, or rename any of these folders or their contents,
unless you are sure you know what you are doing, as this could cause
problems with running MacPerl.
|
|
The Installer has also installed the
Internet Config application in a sepa-
rate folder, named for the current version of Internet Config (e.g., Internet
Config1.4).
|
|
Internet Config can be used for many things, including setting up standard
preferences for many Internet programs, such as USENET news or email
readers. It can also be used to assign helper applicationsfor reading various
types of files such as text, html, and pod. We'll use Internet Config later in
this chapter to assign Shuck as the helper for reading pod files.
|
|
A Walk Through The Menus
|
|
Now that you've familiarized yourself, at least a little, with the contents
of the MacPerl folder, it's time to try out MacPerl. Double click the MacPerl
application icon to launch MacPerl. The Menu bar should contain the stand-
ard File, Edit, and Helpmenus (Balloon Helpprior to Mac OS 8.0), as well as a
new menu called Script. If you have previously installed the Internet Con-
fig extension, you may see an additional menu as well.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The Filemenu should look familiar to you. Most of the menu items will be
greyed-out(inactive) until you create a new MacPerl document. The items in
the File menu are fairly standard, performing much the same actions as
their counterparts in other Macintosh applications.
|
|
You may not recognize the Revertitem. This causes MacPerl to revert to
the last saved version of a MacPerl document (or not, if you choose Cancel).
|
|
The Editmenu should also look very familiar, although you probably
won't recognize the Jump to...or Format...items. We'll come back to
these later. Again, many of the menu items will be greyed-out. Most of
these will become active when you begin to work on a new document.
|
|
If you have already installed Internet Config, you may see a menu between
the Editand Scriptmenus, named for the text editor (e.g., SimpleTextor
BBEdit) which has been selected as the Internet Config editor helper.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The next menu is the Scriptmenu, which drives MacPerl, letting you run
the scripts (programs) you write or get from other people. Let's look at each
item in the Script menu:
|
|
-
Run Script... brings up a dialog allowing you to choose, and run, a
script you may have stored on disk.
|
|
-
Run Front Window runs the script in the frontmost MacPerl window.
The menu item name will change to reflect the actual name of the script
window. If there is no active script window, this item is inactive.
|
|
-
Syntax Check... brings up a dialog allowing you to choose, and per-
form a syntax check on, a script you may have stored on disk. The script
will not be run, but is simply checked for syntactic errors. It is often use-
ful to syntax-check a new script before attempting to run it.
|
|
-
Check Front Window performs a syntax check on the script in the
frontmost window. Again, the menu item changes to reflect the actual
name of the window; this item is only active when there is a window
available. The script is not run.
|
|
-
The next three items, Compiler Warnings,
Perl Debugger, and
Taint Checks are options you can set before running scripts. The
Compiler Warnings option provides additional warnings of potential
problems and incorrect code.3Taint Checksmonitor the use of outside
(i.e., tainted) data in controlling program activities. This is veryuseful
when you are writing CGI scripts. The Perl Debuggerprovides a com-
plete debugging environment for searching out the cause of errors in
scripts. For now, we recommend you select and check Compiler Warnings
and Taint Checks but not Perl Debugger.
|
|
-
The last item, One Liner,
allows you to specify and run one line of
MacPerl code. This isn't as powerful as writing a script, but it can come
in handy on occasion. Note that One Liner
requires Unix-style Perl "one
|
|
|
|
3If this setting is not checked, only fatal errors are noted. Note that setting this option
is the same as using the -wswitch inside each Perl program.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
liner" syntax.4The One Linerdialog is written in MacPerl; you can find
the script in the MacPerl Scriptsfolder inside the MacPerl folder.
|
|
|
|
On-line Help - Installing Internet Config
|
|
The last menu is the Helpmenu.5The Help menu provides links to Mac-
Perl's extensive online help files.
|
|
Most of the help files are in pod format and are best read with the Shuck
application. MacPerl uses the Internet Config extension, included in the
MacPerl distribution, to tell it which helper applicationto use in browsing
the help files.
|
|
If you select one of the Help topics (e.g., MacPerl Overview) and you have
not installed Internet Config (or have not set up Shuck as your helper appli-
cation), you will get the following dialog:
|
|
|
|
If Internet Config has not been installed:
|
|
If you have never installed Internet Config, you should install it. Open the
InternetConfigfolder that was installed along with MacPerl and double-
|
|
|
|
4One Liner also relies on the presence of AppleScript; early versions of System 7,
specifically those priorto 7.5, may not have AppleScript installed by default.
5Prior to Mac OS 8.0, the Help menu is found under the Balloon Helpicon at the right-
hand end of the menu bar.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
We encourage you to peruse the online help information. The pod files con-
tain a wealth of useful information about the Perl language. In particular,
you should be sure to refer to the Macintosh-specific help topics.
|
|
A New Menu
|
|
When Internet Config has been installed, you should see an additional
menu between the Editand Scriptmenus. This menu represents the editor
helper chosen in Internet Config, and allows you to edit MacPerl scripts
using an alternative to the default MacPerl editor. You may want to launch
Internet Config again and set the editorhelper to your preferred text editor,
such as Alpha or BBEdit.
|
|
Running A Script
|
|
Next, let's create a very simple script, save it, and run it. (It's not strictly
necessary to save a script before running it, but this is a good habit to get
into.) We'll do this both to get a feel for how MacPerl works and to observe
the resulting changes in the menus.
|
|
Create a new document (using the Filemenu). You'll see a new Untitledwin-
dow and many of the formerly greyed-out items in the File, Edit, and Script
menus will now become available.
|
|
Note that the Scriptmenu items now refer specifically to Untitled, rather
than to the generic Front Window.
|
|
|
|
You'll also see a new menu appear - the Windowmenu. The Windowmenu
keeps track of all MacPerl windows. A check mark is placed by the name of
the frontmost window, in this case, Untitled. The MacPerlwindow is the
window which shows output from your scripts; it is in italicfont because we
have no output at the moment.
|
|
Creating a script
|
|
At the cursor in your Untitledwindow, type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print 'hello';
|
|
If you don't like the default font or size, use the Format...item in the Edit
menu to choose something you prefer. We strongly suggest, however, that
you use a monospace(fixed-width) font such as Courieror Monaco.
|
|
|
|
Next, save the file as myscript(or any name you prefer). Note that the
Scriptand Windowmenu items change again to reflect the new name. Select
Run "myscript"from the Scriptmenu. A new window, entitled MacPerl,
will appear, containing the text
|
|
hello
|
|
Note that the MacPerlitem in the Windowmenu is no longer in italics.
|
|
Close the MacPerlwindow and edit the script in the myscriptwindow,
deleting one of the quote marks, ', to produce:
|
|
print 'hello;
|
|
Run myscriptagain. This time, the MacPerlwindow will contain an error
message:
|
|
# Can't find string terminator "'" anywhere before EOF.
File 'HD:MacPerl :myscript'; Line 1
|
|
The message tells you that MacPerl expected to find a closing quote mark, ',
but that the interpreter reached EOFor End Of File, without encountering
the quote. If you had selected Syntax Check "Untitled", you would have
received the same error message. Try it!
|
|
Select the line6that says:
|
|
File 'HD:MacPerl :myscript'; Line 1
|
|
|
|
6Depending on the location of your script, the pathname you see for the file will vary.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
then pull down the Editmenu. The Jump To...item is now enabled and has
changed to refer directly to the specific file name and line number in the
error message.
|
|
Select Jump to "myscript". MacPerl will jump to, and highlight, the line in
your script window where the error was found.
|
|
Because you saved myscriptbefore deleting the quote mark, you should be
able to revert to the previously saved version, using the Revertitem under
the Editmenu. Try it.
|
|
Check The Preferences
|
|
Before we leave the Installation chapter, you might want to take a look at
the MacPerl preferences. The default preferences should be fine for now, but
it's nice to know what they do.
|
|
The Librariespreference tells MacPerl where to look for libraries of addi-
tional code. Each pathis a sequence of folders, starting with the disk vol-
ume, that leads to the location of the library files.
|
|
|
|
Librariesalready contains one path - the path to the libsfolder in the Mac-
Perl folder you just installed. You'll add a few more paths to the libraries
if you start installing and using Modules (discussed in detail later in this
book). For now, just familiarize yourself with this preference dialog so that
you can find it when you need it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(also known as the shebang8line) provides special instructions to the Perl
interpreter when the script is run. An example of a #!line might be:
|
|
#!perl -w
|
|
The word perlis required.9The option, -w, tells Perl to turn on extra warn-
ings. These warnings will tell you about non-fatal errors which could cause
execution problems. Many other options (or switches) are available, but not
all of them are meaningful (or even supported) by MacPerl. To get a list of
all possible Perl switches, execute a script beginning with
|
|
#!perl -h
|
|
We recommend that you click the box to check for the #!line. Note that
the #!line is necessary if you plan to use the MPW perltool and make any
of your scripts directly executable.
|
|
|
|
The Inputpreference tells Perl whether or not you want to enable inline
input. This Preference is only meaningful under Japanese systems; it allows
characters to be composed directly in the MacPerl TextEditwindow instead
of in a separate floating window.
|
|
The Inputpreference has been confirmed to work well on a Macintosh run-
ning the Japanese Language Kit, using the Kotoeri Input-System and the
Osaka font. It should also work with other settings.
|
|
|
|
8Perl jargon is rife with puns, many of which have Unixish origins. Shebang, aside
fromits colloquial meaning (as in "the whole shebang"), comes fromthe Unix "shell",
coupled with a "bang" (exclamation point). The New Hacker's Dictionaryis a won-
derful compendium of such jargon, along with amusing and edifying hacker folklore.
9If you intend to run your script on a Unix system as well, you may specify the full
pathname to the perlapplication on the Unix system. MacPerl doesn't care if you use
a full pathname; it only looks for the string "perl".
|
Copyright © 1997-1998 by Prime Time Freeware. All Rights Reserved.