On Jan 31, 2004, at 7:11 PM, Christopher Palmer wrote:

I'm in a bit of bind here.  I started an online intro Perl course, and
the current task is to make sure my machine is loaded with the latest
versions of DBI.pm, CGI.pm, and the DBD of my choice.

That's a pretty bogus course, IMHO. Module installation can get hairy, and saddling a newbie with it as one of their first tasks isn't very friendly.


Okay. This stuff is covered in detail in "perldoc perlmodinstall", so I'll just hit the high points here. Oh, and if you didn't know, "perldoc" is a documentation reader similar to "man", that takes the name of the perl documentation page, or the name of a module, as an argument.

So, the first thing you want to do is configure the CPAN shell. Since your course is Windows-centric, they may have mentioned ActiveState's PPM tool for package management; the CPAN shell is a similar tool that's used in UNIX environments. You need to run it as root, so start it like this:

sudo cpan

It will ask you a number of questions about where you want to get your modules and so on. For the most part, the defaults are fine, and you can simply accept them by hitting "return." You do need to choose a mirror (or three) however; this is where you'll be downloading your modules from.

1) How can I tell what versions of modules I have installed, if any,
aside from finding, say, CGI.pm and opening it up in BBEdit to check?
(which is what I did anyway)

In the CPAN shell:


i ModuleName

This will give you information about ModuleName, including the currently installed version (if it's installed), and the version available from CPAN.

Note that the Perl that ships with Panther already includes a very recent CGI module, so you don't need to install it unless you want the absolute latest.

Also notice that the name of the module is "CGI" - not "CGI.pm". The CGI module, like most modules, does include a file that has the name of the module + ".pm", but the extension isn't part of the module name, and isn't used in the CPAN shell.

2) How can I install DBI.pm?

In the CPAN shell:


install ModuleName

This will attempt to download and install ModuleName.pm using the default, standard procedure. This should work fine for DBI, but DBD::mysql will need some hand-holding.

4) I tried to install DBD::mysql, and I get this at the very end:

Warning: prerequisite DBI 1.08 not found.

One of the more useful aspects of the CPAN shell is that it manages prerequisites for you. You can configure it to (never/always/ask about) installing them; I configure it to ask, because I'm a little bit paranoid. If you're the trusting type, you can tell it to always install them without asking, or if you're *really* paranoid, you can tell it to never install them.


One thing you'll need to do before installing DBD::mysql is install MySQL itself. The simplest way to do that is via Fink. You'll also need the related -dev package from Fink, which includes the headers and libraries you'll need. If you intend to run the DBD::mysql module's self-tests, which is advisable, you'll need to start up mysql and set the root password.

As I said before, DBD::mysql needs more hand-holding than the default 'install ModuleName' will provide. More to the point, extra parameters need to be passed to "Makefile.PL" when you run it. To do this, use the CPAN shell's handy "look" command:

look DBD::mysql

This will download the latest DBD::mysql module, unpack the tarball, and open up a subshell in the build directory. First, read the INSTALL.html file that's included with DBD::mysql; it gives a complete list of options. The most common problem, however, is that since you're running the self-tests as root, MySQL will want a password. To provide that password, you use the --testpassword option, like this:

perl Makefile.PL --testpassword=blah

There are many other options. You can tell it where to find mysql_config (if it's not in your PATH), what database to use for the self tests, what user to log in as, the host name and port to connect to if you want to run the tests against a remote server, etc.

Once you've configured it with the options you need, you can proceed by running:

make
make test

If "make test" succeeds, you can install the module with:

make install

If "make test" fails one or more tests, you have a choice to make. If you understand what tests failed, and you're certain that the feature being tested won't apply to what you're doing, you can go ahead and do the "make install" anyway. For that matter, you can skip the "make test" step entirely, and install a module without running its self-tests; I would recommend living that dangerously, but you can do it.

(I just noticed that there's a DBD::mysql package available via Fink. I haven't tried it, but it might be a viable option if the above seems too imposing.)

Error: Unable to locate installed Perl libraries or Perl source code.

This message usually indicates that you haven't installed the developer tools. You're using Panther, so make sure you've installed Xcode, not Project Builder. If you've upgraded from Jaguar (or earlier), you'll need to upgrade the developer tools also.


my command line skills are a bit rusty.

They'll get better. ;-)


Also, are there any other resources for Perl on OS X out there?

For the most part, Perl on Mac OS X is like Perl on any other UNIX. This is a good place to ask about any differences. Be sure to check the list archives first, though - a lot of this stuff has been discussed to death, so you can often get an immediate answer from the archives instead of waiting for someone to get your email and respond to it.


sherm--



Reply via email to