Don't be alarmed. Perl is soft and cushy. It's the easy way to get things done because in Perl, 'There's More Than One Way To Do It'. Perl, as a language comes with decades of perl users contributing their code to a common structured repository and also comes with a tool (the perl CPAN module actually) that can connect to, download and install perl modules, verify the modules are intact with MD5, and download all the other modules the one you're installing depends upon, all automatically. That takes out a lot of the guesswork and lets you get a lot done, fast. Find the right perl module and most of the heavy lifting is done for things like connecting to a web server or database, downloading files and data and searching it for the information you need.

Perl has one of the best (if not THE best) regular expression implementations of any language and is fantastic at pattern matching, and pretty darn good at just about everything else. It's my language of choice for the automation and integration and administration work I do. 

Installing Perl

Here's what you need to get up and running and writing your code in under 1 hour (20 minutes if you're good).

  1. Log into the computer of your choice where you will be running perl scripts.
  2. Download and install Perl
    1. Windows
      On Windows, there's more than one path:

      • Active State Perl - For general scripting, Active State Perl is the way to go if you're wanting to get started in a hurry. Active State perl comes with their Perl Package Manager (PPM) which connects to Active State's perl module repository which contains a large number of popular perl modules pre-compiled for the Windows/Active State platform.  You can download the Active Perl binary package from Active State's website (http://www.activestate.com). Once you have downloaded the installer, run the installer and take all the defaults.
      • Strawberry Perl - The Strawberry Perl package is the version of perl that is most compatible with the standard perl developed for Unix and Linux and is in fact Larry Wall's preferred version of perl to work with (at least according to the Strawberry folks).
      • Cygwin and standard Perl - Cygwin itself is a unix-like environment for computers running Windows operating systems. When you install Cygwin, you add most of the Unix/Linux command line tools to the MS-DOS command line.  Cygwin comes with it's own built-in package deployer. One of those packages is perl. Another built-in is MinGW which can be used to compile software in the Cygwin environment.  You can install perl from Cygwin and update perl from the CPAN repository just as you would in Linux.  The catch with Cygwin is that it changes drive paths from the standard Windows C:\ to plain old / like on  *nix systems, which can throw you off when working in Cygwin, and in perl.

    2. UNIX:

      The easy way to install is to browse to the CPAN ports archive for perl and download it from there. Simply click the link for your operating system and version and follow the links. Perl is included as part of a standard operating system installation on many operating systems.

      Again, Active State's perl distribution for Windows and Mac OS X, but OS X is now directly supported, since it is in essence a *nix-based operating system now.

    3. Linux

      Most versions of Linux come with Perl and if they don't the Linux package repository does. You can install and update the core Perl binaries from the Linux repository.

      Example:
       
      bash$ rpm install perl

       

  3. Once you've installed the true Perl binary, you need to run the CPAN module either as root, the account that installed perl or a user who has access to the perl files and binaries. You can update perl modules from CPAN with the following commands:

    bash$  cd /
    bash$  sudo -s
    Password: ********
    bash#  perl -MCPAN -e shell


    When launching perl with the CPAN Module (-M) from the command line (-e shell), capitalization is important.

    CPAN is a module that is designed to make it easy to download and install perl modules from the CPAN archive. CPAN will walk you through setting itself up if you haven't done it already. Most of the questions you will be asked have to do with where certain binaries are found on the system, such as make. Accepting the defaults as offered by the script has worked for me every time so far.
  4. If you're using the Active State distribution, use the ppm module included with the package to update the Active State perl distribution. You can run CPAN from the Active State distribution, but you don't have make or gzip which perl requires to unpack and build the downloaded modules.

Update Critical Perl Modules

  1. UNIX/Linux
    1. The first thing you want to update is the CPAN module itself. The CPAN module is included with Perl and can be updated or downloaded from CPAN www.cpan.org. To get CPAN updated run the following command from within the CPAN prompt that we started with the previous perl command.

      cpan> install Bundle::CPAN

    2. Follow the prompts. It may already be up to date, if so, jump to the next step. Updating CPAN has little impact on Perl's behavior. This should be transparent to your current perl scripts.
    3. Next, we reload the CPAN libraries to refresh them while we're still running CPAN:

      cpan> reload cpan

      This updates the current perl libraries for CPAN without having to exit CPAN.

    4. install the MD5 library

      cpan> install Bundle::MD5

    5. Install IO::Stty. This is not a manadatory prerequisite but some scripts and tools work better with this module installed. It also makes the Expect module run a bit more cleanly.

      cpan> install IO::Stty

      And that should do it. Also... CPAN has built in help. Just type '?' or 'help' at the CPAN prompt and press enter.

  2. Windows
    1. Use Active Perl's "Perl Package Manager" called 'ppm'. Simply run it from the command line.
      Using Active State's PPM:
      http://docs.activestate.com/activeperl/5.10/faq/ActivePerl-faq2.html

    2. Install:
      1. Bundle::CPAN
      2. MD5

    3. Install the Missing Modules from the Active State build. The cryptographic modules are missing due to Canadian export laws and various vendor licensing or technical implementation problems.
      1. Crypt-Blowfish, Crypt-Blowfish_PP
      2. Crypt-CAST5, Crypt-CAST5_PP
      3. Crypt-DH
      4. Crypt-DSA, Crypt-RSA
      5. Crypt-GPG
      6. Crypt-GOST, Crypt-GOST_PP
      7. Crypt-IDEA
      8. Crypt-OpenPGP, Crypt-PGP2, Crypt-PGP5, Crypt-PGPSimple
      9. Crypt-OpenSSL-DSA, Crypt-OpenSSL-RSA, Crypt-OpenSSL-SMIME
      10. Crypt-RC4, Crypt-RC5, Crypt-RC6
      11. Crypt-RIPEMD160
      12. Crypt-Rijndael, Crypt-Rijndael_PP
      13. Crypt-Serpent
      14. Crypt-Twofish, Crypt-Twofish2, TwoFish
      15. Crypt-SSLeay, Net_SSLeay
      16. GD module

    4. This enables you to use some (but not all) of the CPAN modules.

    5. You may need to add 'make' to your Windows environment. At last check, the file was available from here:
      (URL DELTED - Sorry, Microsoft pulled the file, so I'm trying to find another way to get it.)
 

Searching the CPAN archives

This section applies primarilly to UNIX/Linux systems. While it is possible to run CPAN in Active State's perl distribution, it's not recommended unless you know what you're doing (and you wouldn't be reading this if you did).

To search the CPAN archive, you can launch CPAN:

# perl -MCPAN -e shell

..and then search for modules in the CPAN archive using the command:

cpan> i /<module name>/

Built in Online Help

Applies to All Platforms

Most everything in Perl comes with built-in documentation. That documentation is in 'plain old documentation' format or pod format. The command perldoc is installed with perl and allows you to extract and read this documentation. The documentation for most modules is stored inside the perl module itself as inline comments on the code.

If you want documentation about an installed module, you can use the 'perldoc' command which basically greps/formats comments included in the modules and pakges. Documentation for most things in perl is usually excellent and almost always provide sample code to explain how to call methods and functions.

For example:

[user@localhost]/export/home/user> perldoc Net::SCP::Expect

You can also get documentation on built-in Perl functions using a variation of this command:

perldoc -f <function>

To get started learning about Perl, type:

perldoc perl

 

Testing and Debugging

Perl has a built in debugger covered quite fully in Perl itself. Execute the following command to access the debugger documentation:

perldoc perldebtut

 

You can test pieces of Perl code to see what they do by executing them directly on the command line:

perl -e { ..statements.. }

 

You can use the -w flag at the beginning of your perl script which generates warning output for you to use in debugging the program.

While learning to script or program in Perl, I highly recommend that you 'use strict;'. This forces you to learn good perl syntax and form by forcing you to declare variables and instantiates them correctly so that you don't overwrite a global variable with a local variable.

 

Websites


http://www.cpan.org
http://www.perl.com
http://www.perl.org
http://www.activestate.com

Using Active State's PPM:
http://docs.activestate.com/activeperl/5.10/faq/ActivePerl-faq2.html

 

 

Search

Donations

Free Training