How do I install new scripts | modules | extensions?

(Thanks to Ilya Zakharevich <ilya@math.ohio-state.edu> for pointing out that perl code comes in a variety of flavors and some code requires more work than others to install. Hence I have expanded this topic and will refer to three distinct categories here: Scripts Modules and Extensions:)

Scripts

A "self-contained" script needs little modification (in principle!) to run. It is a good idea to check the #! line at the very top of the file to reflect your local perl setup (e.g. #!/usr/bin/perl -w (change to) #!/usr/gnu/local/perl -w or what have you). There are allegedly "more portable" ways to invoke the perl interpretor as well - they are more fully documented in the perl FAQ and the perlrun(1) man page, however.

Other things you do not want to forget when trying to run a perl script include giving yourself permission to do so, e.g.:

    chmod u+x newscriptname
You also want to be sure your DISPLAY environment variable is set up properly when attempting to run a perl/Tk script. You may also need to look at the xhost(1) or the xauth(1) man pages for setting up your X-display properly.

If you are still experiencing difficulty check to be sure that extraneous /newsgroup|e-mail|HTML headers|footers|markup//; are not in the file and that you have on hand all that is requireed or useed by the script (if not you may need to install a module - or even a perl4 style lib.pl file).

Modules

Check out the module - make sure it is OK and will run on your system - does it require a specific location? For testing purposes (always a good idea) or if you do not have root priveleges set the file in a directory that you do have write access to and try to include it in a test script. Assuming you have a module to test called "Foo.pm" and are simply running the test script in the same directory as the module begin by adding to the @INC array like so:
    #!/usr/bin/perl -w
     BEGIN { @INC = ("$ENV{'PWD'}",@INC); }
     use Tk;
     use Foo;
or
    #!/usr/bin/perl -w
     use lib $ENV{PWD};
     use Tk;
     use Foo;
Another approach is to set either the PERLLIB or PERL5LIB environment variable from your shell. This method allows invoking the test script from within a number of different directories without having to edit a hard coded use lib or push(@INC,".") kind of statement within the script. Yet another way to do it is with the -I switch on the command line like so:
    perl -Ipath/to/Foo -e fooscriptname

After a successful test; if you are a system administrator, or have root priveleges, or are modifying your own copy of perl; then copy it to the perl5/Tk directory. Depending on how the module was written it should be possible to use it either with the use Tk; statement itself or with an explicit use Tk::Foo; (for module perl5/Tk/Foo.pm).

Extensions (Overgrown Modules)

These may come as a multi-file kit (tape archive usually) and may require a C compiler for part of the installation (Tk-b# itself falls into this category). You know you have an Overgrown Module (Extension) when there is one or more files with an .xs extension (perl->C meta code) and a Makefile.PL (perl->make meta code). One invokes the perl MakeMaker on the file called Makefile.PL in order to create a Makefile via:
    perl Makefile.PL
You may now run make on the resultant Makefile - but the details of this process are module dependent and should be documented in a README or an INSTALL file. A very standard perl extension requires 4 (or 5 if making static) standard commands to make and install:
    perl Makefile.PL
    make
    make test
    make install
If you have the appropriate CPAN and FTP modules already installed you can retrieve a module from CPAN and carry out all of the above steps with a perl one-liner like this:
    perl -MCPAN -e 'install "Foo"'

Previous | Return to table of contents | Next