The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers > Answers to Frequently Asked Questions > Tips and Tutorials
Google UNIX.COM


Tips and Tutorials Helpful articles from our Users.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
I am one of the newbies, please advise sanlen UNIX for Dummies Questions & Answers 3 09-17-2007 04:45 AM
CPAN: using only wget to d/l modules? dangral Shell Programming and Scripting 2 07-12-2007 09:49 AM
Newbies problem greenhorn UNIX for Dummies Questions & Answers 5 02-08-2006 05:02 PM
CYGWIN/CPAN install of Expect.pm white222 UNIX for Dummies Questions & Answers 1 07-20-2005 05:27 PM
Specially for unix newbies clemeot UNIX for Dummies Questions & Answers 2 09-11-2001 09:16 AM

 
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-15-2004
Registered User
 

Join Date: Jun 2004
Location: The True North, Strong and Free
Posts: 24
Stumble this Post!
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.
__________________
There is no reason for any individual to have a computer in his home.
Ken Olsen (1926 - ), President, Digital Equipment, 1977
Google The UNIX and Linux Forums
Forum Sponsor
 

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0