• No results found

EGTDC Perl Course 2004

N/A
N/A
Protected

Academic year: 2021

Share "EGTDC Perl Course 2004"

Copied!
10
0
0

Loading.... (view fulltext now)

Full text

(1)

EGTDC Perl Course 2004

Making use of CPAN modules Perl on other platforms

Tim Booth : [email protected]

(2)

CPAN Recap

• "Comprehensive Perl Archive Network".

• Holds virtually every Perl module, among other things.

• Access via the web (http) and by the CPAN shell.

– search.cpan.org is probably your first point of call.

• Most modules are standardised to make them easy to use right away:

– Documentation in ' perldoc'  format.

– Standard installation procedure

– Self­testing

(3)

CPAN and modules

• CPAN contains around 2860 modules ­ bits of code that can be plugged into your  scripts.  Some are small, some complex.

• Need to interface with a database?  Use the DBI/DBD modules.

• Need to make webpages with Perl?  Use the CGI module.

• Need to make a graphical interface?  Use the Tk module.

• Need to do bioinformatics?  Use the BioPerl modules!

• To use an installed module you " use module_name; " in the same way as you 

" use strict; "

• Modules can be installed in 2 ways – Manually, from source

– From CPAN, using the CPAN shell.

(4)

Installing modules from source

• On Bio­Linux, log in as manager to install modules system­wide

• Modules are distributed as .tar.gz files.

• Download the module to the manager' s home directory.

• if you are missing components required for the module to work you will be told  at the 2

nd

 step below. 

• Always check README or INSTALL files before installing.

tar -zxvf test_module.tar.gz

cd test_module #or whatever directory was created perl Makefile.PL #note the capitalisation

make

make test

sudo make install

(5)

Installing modules with CPAN

• sudo perl -MCPAN -e shell  on the command line launches the CPAN  interface.

• CPAN shell is very clever as it automtically downloads, builds, tests, installs and  resolves dependencies (ie if one perl module requires another).  If you specify a  module you already have then it will be updated to the latest version.

• Bio­Linux has CPAN set up, for other systems you may need to configure it and  install dependencies first.

• Full CPAN documentation is here:

http://theoryx5.uwinnipeg.ca/CPAN/data/CPAN/README.html

• Great for getting BioPerl up and running fast:

– install Bundle::BioPerl

(6)

Installing modules as a regular user

• You do not have to be the system administrator to install modules for your own  use.

• You may also want to test new or updated modules in a temporary directory.

• CPAN can still help, but there is some fiddly setting up to do.  You will probably  find it easier to install the modules manually:

tar -xvzf downloaded_module.tar.gz ; cd downloaded_module_dir perl Makefile.PL PREFIX=~/myperl

make

make test && make install

• This puts the module in the ' myperl'  subdirectory of your home dir. Don' t forget 

to include this in your @INC path to use the module!

(7)

Setting the @INC path

The global array @INC lists all the places where Perl will look for modules, but you should not modify it directly. For example, to use modules in your ~/perl/lib/5.8.0 directory, do one of the following:

Set the PERL5LIB environment variable at the shell prompt:

export PERL5LIB=$HOME/perl/lib/5.8.0 perl myscript.perl

Run perl with the ­I option

perl -I$HOME/perl/lib/5.8.0 myscript.perl

Put a ' use lib'  statement in your script.

#!/usr/bin/perl

use lib “/home/user1/perl/lib/5.8.0”;

use My::Module;

(8)

Checking installed modules

All good modules will self-test before they install, so you just need to verify that Perl can find the new module. Simply run:

perl -e 'use Config::Simple'

Specifying the name of the module to test.

If this succeeds you will get no output, otherwise you will get an error.  

The error message lists the directories where Perl has looked for modules, and 

you will need to add the correct directory to this list.  This will apply especially if 

you are installing modules in a user directory or some other temporary location.

(9)

CPAN as a regular user

You can still use CPAN to install modules in your home directory, but it is fiddly! On Bio- Linux you would have to set up CPAN as follows:

Make a local directory for CPAN:

mkdir -p ~/.cpan/CPAN And generate a config file:

sed -e "s/egdcmanager/$USER/" /usr/lib/perl5/5.8.0/CPAN/Config.pm

>HOME/.cpan/CPAN/MyConfig.pm Start CPAN and set some settings:

perl -MCPAN -e shell (now in the CPAN shell)

o conf makepl_arg "PREFIX=~/perl/lib"

o conf commit

Now install your module:

install Some::Module

(10)

Perl on Windows

• If you want to use Perl ­ but have no UNIX machine ­ don' t panic!

• Perl runs on Windows too (in fact, Perl runs on just about anything).

• The most popular version comes from www.activestate.com 

• Download "ActivePerl" a free binary distribution of Perl for Windows.

• Uses "ppm" the "perl package manager" to control module installation ­ it' s like  the CPAN shell only 10x easier.

• Use "notepad" or a similar text editor to write your scripts.

• If you want to mimic a Unix environment in Windows for your programming 

needs, you might want to look at www.cygwin.com which gives a Linux like 

environment and development software you would expect on a Linux system.

References

Related documents

In our experiments, HyScaleII has lower packet loss ratio and higher average aggregate throughput by an average of 50% and 13.8% respectively as compared to HyScale [17]..

By calculating control trajectories for the UAV’s flight trajectory and the gimbal’s attitude in the same controller, a high degree of system flexibility is introduced where the UAV

The organizational effective factors on technological entrepreneurship process in active SMEs in nanotechnological field include eight dimensions as organizational

As drafted, the requirements miss the enormous diversity in the missions and opportunities pursued by individual law schools; in the backgrounds and professional goals of

The remainder of this section describes the methodology used to import the baseline travel demand model data, deploy ITS projects, adjust impact values and determine proposed

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ]... Previous: What's in This Book

Svrha opisivanja položaja Kurda i njihovih političkih stranaka u Iraku, Iranu, Siriji i Turskoj je pokazati da je tradicionalna podjela na klanove zamijenjena političkim

Alternatively, you can state explicitly which variables and subroutines you want to export when you load the module, using the general form:.. use Module qw( $variable