PERL & CPAN Intro for Newbies


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Answers to Frequently Asked Questions Tips and Tutorials PERL & CPAN Intro for Newbies
# 1  
Old 06-15-2004
PERL & CPAN Intro for Newbies

So you want to learn a unix scripting language that you'll be able to use in any situation? Perl is your answer !

This is a little intro to installing CPAN modules. If you don't know what CPAN is, check out http://search.cpan.org/. Basicly, it is a massive archive of perl libraries that will allow you to do pretty much anything. (Once I wrote a shoutcast-style streamer in perl with a web front end, automatic down sampling and ogg->mp3 conversion, but that is a whole other story.)

Using CPAN is easy.

Code:
-su-2.05b# perl -MCPAN -e shell

/usr/local/lib/perl5/5.8.2/CPAN/Config.pm initialized.

...

The -M flag tells perl to load a perl module. -MCPAN is the same as putting 'use CPAN;' in your script.

The -e flag tells perl to execute a command. In this case, the CPAN module exports a function called 'shell'.

When you first run the CPAN shell, it'll ask you a bunch of questions about where to find a mirror, and what tar program to use, etc. You can use defaults if you don't know the answer to some of the questions.

Once you are at the cpan> prompt, you can start issuing commands. '?' will list all the commands.

Code:
cpan> ?

Display Information
 command  argument          description
 a,b,d,m  WORD or /REGEXP/  about authors, bundles, distributions, modules
 i        WORD or /REGEXP/  about anything of above
 r        NONE              reinstall recommendations
 ls       AUTHOR            about files in the author's directory

Download, Test, Make, Install...
 get                        download
 make                       make (implies get)
 test      MODULES,         make test (implies make)
 install   DISTS, BUNDLES   make install (implies test)
 clean                      make clean
 look                       open subshell in these dists' directories
 readme                     display these dists' README files

Other
 h,?           display this menu       ! perl-code   eval a perl command
 o conf [opt]  set and query options   q             quit the cpan shell
 reload cpan   load CPAN.pm again      reload index  load newer indices
 autobundle    Snapshot                force cmd     unconditionally do cmd


Lets start with a simple search. Lets say I want to find a module that will let me encrypt and decrypt messages using a blowfish cipher. I would use one of the search commands 'a, b, d, m or i' (Author, Bundle, Distribution, Module or Any). Since I know I want a module, I'll use 'm'.

Code:
cpan> m /blowfish/
Module          Crypt::Blowfish (D/DP/DPARIS/Crypt-Blowfish-2.09.tar.gz)
Module          Crypt::Blowfish_PP (M/MA/MATTBM/Crypt-Blowfish_PP-1.12.tar.gz)
Module          Net::SSH::Perl::Cipher::Blowfish (D/DR/DROLSKY/Net-SSH-Perl-1.25.tar.gz)
3 items found

This tells me there are 3 modules with the name 'blowfish' in them. Crypt::Blowfish and Crypt::Blowfish_PP are one of the ones I want. But which one should I use?

By convention, some module that are written in pure perl (no extra binary code) have a _PP postfix. Pure Perl modules are often slower then their binary counterparts, but are often more compatible and easier to install as they have no other dependancies (not even a C compiler).

So I'll decide to go with the slower, easier to install version since it'll only be used to in my small program for encrypting and decrypting small amounts of data.

Code:
cpan> install Crypt::Blowfish_PP
Running install for module Crypt::Blowfish_PP
Running make for M/MA/MATTBM/Crypt-Blowfish_PP-1.12.tar.gz

...

Writing /usr/local/lib/perl/5.6.1/auto/Crypt/Blowfish_PP/.packlist
Appending installation info to /usr/local/lib/perl/5.6.1/perllocal.pod
  /usr/bin/make install  -- OK

It's all installed. Now what do I do?

I need to learn the API, so I'll go to http://search.cpan.org and search for the new module I just installed. It leads me to a nicely formatted manual-like page (http://search.cpan.org/~mattbm/Crypt...Blowfish_PP.pm)

Now, I am not going to write a simple encrypt/decrypt tool for you (unless you really bug me to), needless to say, it's easy to do. Infact, less then 15 lines of code should do it.

The point is, CPAN is easy to use, the modules are often great, and most importantly, its fun because you can do alot with very little.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Unable to install Perl module via CPAN

Hi, I am trying to install Unicode::String from the cpan shell, and here is what I get: Checking if your kit is complete... Looks good Writing Makefile for Unicode::String cp String.pm blib/lib/Unicode/String.pm cp lib/Unicode/CharName.pm blib/lib/Unicode/CharName.pm... (3 Replies)
Discussion started by: psychomachine
3 Replies

2. UNIX for Dummies Questions & Answers

rsync tutorial for newbies

Hi. Learning rsync from the man pages can be daunting. I wrote this tutorial to make learning rsync easier: rsync tutorial (rsync2u) The rsync tutorial is for new rsync users. Three small backup examples thoroughly explain rsync --link-dest, --recursive, and --exlcude-from options. Enjoy. (2 Replies)
Discussion started by: wolfv
2 Replies

3. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

4. Solaris

2 questions for newbies

Hi I'm totally new to solaris 5.9 Two questions. 1. What is the replacement for /proc/cpuinfo (isn't this part of POSIX). I heard it's psrinfo but it doesn't work. 2. I use ssh - v -X with X tunelling from linux onto a solaris server, but xclock failed. it says won't open display. $DISPLAY is... (6 Replies)
Discussion started by: grossgermany
6 Replies

5. Shell Programming and Scripting

[Perl] How to install with CPAN specified version of module

Hello all, i am searching how to install a module but the question is : howto specify CPAN to install a determined version of the module ? In my case i want to install DBD:Oracle1.14 and not version 1.23 proposed ! Any idea welcome ! :rolleyes: Thanks ! (1 Reply)
Discussion started by: sun_cracker
1 Replies

6. Shell Programming and Scripting

Perl - problem with CPAN module XML::Simple

Hi All, I am trying to run the following program #!/usr/bin/perl # use module use XML::Simple; use Data::Dumper; # create object $xml = new XML::Simple; # read XML file $data = $xml->XMLin("dump.xml"); # print output print Dumper($dump); At first i had the error mesage saying... (5 Replies)
Discussion started by: userscript
5 Replies

7. UNIX for Dummies Questions & Answers

Newbies problem

Hi I am new to Unix and need help. How do I use the $@ in my script to direct the executing of commands on various files. Thanks curious greenhorn (8 Replies)
Discussion started by: greenhorn
8 Replies

8. UNIX for Advanced & Expert Users

Compile error when running Perl cpan

Hello all! I'm trying to compile the GD module for Perl on Redhat AS 4. It fails when trying to link to libjpeg. The machine is a AMD Opteron 64 machine so I figure it's some kind of 32 vs 64bit interference in the lib dir? Any idéas? CPAN.pm: Going to build L/LD/LDS/GD-2.41.tar.gz ... (0 Replies)
Discussion started by: Esaia
0 Replies

9. UNIX for Dummies Questions & Answers

What kind of Linux for the newbies?

I am one of the newbies. I want to load linux on my notebook, however, i am not sure which linux is the most recommend for the newbies. Could you please advise? Thanks you very much for any advise you may give me. Best Regards, SANLEN (2 Replies)
Discussion started by: sanlen
2 Replies

10. UNIX for Dummies Questions & Answers

I am one of the newbies, please advise

I am new to UNIX and Linux. I have some experiences with Windows server. I am thinking to start with those OS (Unix/Linux) and more specifically with the OS for the server. however, i have no idea which one would i start first, unix or linux? Because i also dont know how they are different. ... (3 Replies)
Discussion started by: sanlen
3 Replies
Login or Register to Ask a Question