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
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


Tips and Tutorials Helpful articles from our Users.


Other UNIX.COM Threads 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 Search this Thread Display Modes
  #1 (permalink)  
Old 06-15-2004
Registered User
 

Join Date: Jun 2004
Location: The True North, Strong and Free
Posts: 24
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl 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.
Google UNIX.COM
Forum Sponsor
 



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 11:07 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

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102