Professional Documents
Culture Documents
The newest release of Apples operating system, OS X v10.2 (Jaguar) is filled with many welcome
improvements and additions. The integrated Address Book, improved Mail, System Preference
tweaksall good things. But what really excited me was the new stuff under the hood: bash,
Python, gcc 3, Ruby. About the same time Jaguar was in development, work was finishing up on my
beloved Perl, version 5.8.1.
A quick trip to Jaguars Terminal showed me that this version didnt make it into the default install:
Preparation
If youve installed shell applications before, you know how the process usually goes: download the
source, configure the source, compile the source, and install the source. Perl is no different, but does
require some patience; compiling the package could take you an hour or more, depending on the
speed of your machine.
You need to have Apples Development Tools installed. To learn more about these and how to
download the latest set for free, visit the Development Tools page on ADC.
If you use Apaches mod_perl, youll need to recompile it.
The process described below was performed on a fresh install of Mac OS X v10.2, along with the
Developer Tools. These instructions may not work perfectly on previous versions of Mac OS X.
If, after the installation, you get warnings about missing symbols, you probably have an old version
of Perl (or parts of one) in /Library/Perl. These undefined symbols existed in pre-5.8.1 versions. For
more information on this issue, check out perldelta.
OS X users that have installed Fink may experience various symbol errors when executing certain
Perl operations. More on this can be found in the macosx@perl.org archives.
The Perl install docs state: [Perl 5.8.1] is not binary compatible with releases of Perl prior to 5.8.1.
If you have built extensions (i.e., modules that include C code) using an earlier version of Perl, you
will need to rebuild and reinstall those extensions. Pure Perl modules without XS or C code should
continue to work fine without reinstallation. This means that after installation, some of your
modules (like HTML::Parser, XML::Parser, etc.) may not work out of the box without re-
compilation.
Downloading Perl 5.8.1
The first step is to download Perl 5.8.1 itself. You can find it on any number of CPAN mirrors
worldwide. I opened up the Terminal and entered the following commands (you can replace the
URL below with one that reflects your closest mirror):
rm -f config.sh Policy.shIf you want to experiment with different Configure options, then be sure to
run the following to start afresh (this command duplicates the above deletion, along with cleaning
out stuff created during a Configure):
setenv LC_ALL C
echo "setenv LC_ALL C" >> ~/.tcshrcIf youre curious about what those commands are doing, then
youll want to check the INSTALL file, as well as man perllocale. OS X has one of the necessary
environment variables set (LANG), but without the above, youll get annoying error messages each
time you try to run a script. The above assumes the tcsh shell; if you prefer bash, use echo export
LC_ALL=C >> ~/.bash_profile instead.
Now, enter one of the following commands, depending on where you want Perl installed:
# you want to use the default Perl directories:
./Configure -de -Dperladmin=email@addr.com -Dcf_email=email@addr.com
You may also want to look at -Dotherlibdirs. With this option included in the Configure statement,
you can add more library directories to Perls @INC. For example, if I wanted each of my users to
have their own Perl library, I could use -Dotherlibdirs=~/Library/Perl. If I log in as morbus, Ill be
able to stick my own modules in /Users/morbus/Library/Perl without interfering with the rest of my
Perl installation. Of course, if I didnt use -Dotherlibdirs, Id be able to duplicate the same effect in
my code with use lib.
[cpu:~] user% makeThis command took about 15 minutes on my machine. It should complete with
the following: Everything is up to date. Type make test to run test suite. Again, the install knows
best, so run:
[cpu:~] user% make testThe testing process is a common part of a Perl-related installation. Youll
see a large number of tests run, most returning a status of OK, and some skipped due to our
platform. You should only get two failures, both related to Berkeley DB:
ext/DB_File/t/db-btree...............#
# This test is known to crash in Mac OS X versions 10.1.5 (or earlier)
# because of the buggy Berkeley DB version included with the OS.
#
FAILED at test 0This test, as well as db-recno, fails because OS X ships with an old version of a
common database library (Berkeley DB, version 1.x). Perl gives us more advice concerning these
failures:
# You can safely ignore the errors if you're never going to use the
# broken functionality (recno databases with a modified bval).
# Otherwise you'll have to upgrade your DB library.I wont be showing you how to upgrade your
Berkeley DB library, but bug reports concerning this have been filed both at OpenDarwin.org and
Apple (#2923078 and #3021743). The make test took about ten minutes on my G4 and finished by
saying: Failed 2 test scripts out of 657, 99.70% okay.
[cpu:~] user% sudo make installIf you ran the first Configure command above, youll see a
progression of files installing into /Library/Perl (the Perl modules), /usr/local/bin (the Perl binaries)
and /usr/local/share/man/ (Perl-related documentation). This should finish in less than five minutes.
Modules have been written for every conceivable purpose, from interfacing with database
applications to rendering graphics to parsing various types of specialized files. Fresh installations of
Perl come with a number already installed; you can find them by browsing through the /Library/Perl
directory. But if none of the included modules meet your needs, then CPAN is your next step.
Installing a new Perl module by hand, while not extraordinarily difficult, can be a bit of a hassle. It
involves downloading and unpacking the module, configuring it, and building it, all the while
making sure there are no unresolved dependencies or conflicts between modules. If youre the sort
of person who enjoys that kind of process, go right ahead. There is an easier way to go, however.
CPAN.pm is a Perl module whose purpose is to automate the downloading and building of modules.
It takes care of the tricky situations where certain modules require other modules to run, and those
modules in turn require additional modules, and so forth. It also supports the building and
installation of bundles, which are groups of related modules that work together to handle a
particular set of functions.
[cpu:~] user% sudo perl -MCPAN -eshellIf this is the first time youre running the module, youll
be asked a series of questions about how your system is set up. In most instances, the default
answers will work, but make sure that the network setup questions are answered correctly so that
CPAN.pm can get online and properly fetch new modules. The answers you give will be saved in
~/.cpan/CPAN/MyConfig.pm. If your setup changes, or you think you answered a prompt
incorrectly, you can change your settings by opening that file with a text editor and modifying the
appropriate lines.
cpan>Go ahead and install this Bundle::CPAN thing. Perl modules that are closely related to each
other (like all Digest modules, all Net modules, etc.) are packaged into bundles, creating quick
combined installs. To install Bundle::CPAN, just use this command:
cpan> install Bundle::CPANUltimately, thats all you need to know about installing modules for
your shiny new Perl (and any previous version of Perl, actually). Weve both verified that our Perl
5.8.1 installation is working smoothly and improved our CPAN capabilities. As the above command
executes, youll notice CPAN downloading, extracting, testing, and installing modules and their
prerequisites.
Another useful CPAN command is simply r. Once run, CPAN will search through your Perl
modules, comparing your installed versions with the latest versions available. When finished, itll
show you a compiled list:
cpan> r
Package namespace installed latest in CPAN file
Math::BigFloat 1.35 1.36 T/TE/TELS/math/Math-BigInt-1.61.tar.gz
Math::BigRat 0.07 0.08 T/TE/TELS/math/Math-BigRat-0.08.tar.gz
Pod::Text 2.2 2.21 R/RR/RRA/podlators-1.24.tar.gzTo get up to date, its a simple
matter of issuing install Math::BigFloat, install Math::BigRat, etc.
Another useful CPAN command is force, which will unconditionally execute a command,
regardless of other results. If you recall the caveats at the beginning of the article, modules that have
been built with XS or C code under 5.6.0 wont work under 5.8.1, forcing you to recompile and
reinstall. But what if you already have the latest version of, say, HTML::Parser? CPAN complains:
Before you can use Perl for CGI scripts, you need to start the Apache Web server. If you havent
done so already, go into the Sharing pane under System Preferences and click the button to turn
Web Sharing on. After a few seconds, Apache will start running in the background. You can
abra
mm
abra
mm
abra
mm