Don't be alarmed. Perl is soft and cushy. It's the easy way to get things done. Perl handles the install and resolves all Perl dependencies for you. It will even make sure the packages you install haven't been tampered with at the archive by checking the MD5 hash for you if MD5 is installed.
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).
- Log into the computer of your choice where you will be running perl
scripts.
- Download and install Perl
- Windows
For general scripting, Active State Perl is the way to go if you're wanting to get started in a hurry. Download the Active Perl binary package from Active State's website (http://www.activestate.com). Once you have downloaded it, run the installer and take all the defaults.
- UNIX/Linux:
The easy way 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 for the following operating systems:- BSD (all distributions)
- Sun Solaris 8 (Solaris 5.8) and later
- HP-UX 11.00 and later
- Mac OS X
- IRIX 6.4 and later
If you insist on running Microsoft Windows or cling to Mac OS 9 or earlier, you're out of luck. You'll have to download and install a copy of Perl from elsewhere. I have used the Active State perl distribution for Windows for years and it works quite well; they also make a version for Mac OS X.
- Windows
- Once you've installed the true Perl binary, you need to run the CPAN module as root or an account with root level permissions with the following commands:
% cd /
% sudo -s
Password: ********
# perl -MCPAN -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.
- 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
- UNIX/Linux
- 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
- 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.
- 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.
- install the MD5 library
cpan> install Bundle::MD5
- 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.
- 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.
- Windows
- 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
- Install:
- Bundle::CPAN
- MD5
- 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.
- Crypt-Blowfish, Crypt-Blowfish_PP
- Crypt-CAST5, Crypt-CAST5_PP
- Crypt-DH
- Crypt-DSA, Crypt-RSA
- Crypt-GPG
- Crypt-GOST, Crypt-GOST_PP
- Crypt-IDEA
- Crypt-OpenPGP, Crypt-PGP2, Crypt-PGP5, Crypt-PGPSimple
- Crypt-OpenSSL-DSA, Crypt-OpenSSL-RSA, Crypt-OpenSSL-SMIME
- Crypt-RC4, Crypt-RC5, Crypt-RC6
- Crypt-RIPEMD160
- Crypt-Rijndael, Crypt-Rijndael_PP
- Crypt-Serpent
- Crypt-Twofish, Crypt-Twofish2, TwoFish
- Crypt-SSLeay, Net_SSLeay
- GD module
- This enables you to use some (but not all) of the CPAN modules.
- You will need to add 'make' to your Windows environment. At last check, the file was available from here:
http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe
- Use Active Perl's "Perl Package Manager" called 'ppm'. Simply run it from the command line.
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