Perl Tutorial
Fundamentals
Input and Output
Control Flow
Arrays and Lists
Hash
Scalars
Strings
Object Oriented Programming in Perl
Subroutines
Regular Expressions
File Handling
Context Sensitivity
CGI Programming
Misc
Setting up Perl on your machine involves a few steps, from installing Perl to ensuring the environment is correctly configured. This tutorial will walk you through the installation and environment setup for Perl.
Perl comes pre-installed on macOS. However, to get the latest version:
brew install perl
Perl is usually pre-installed on most Linux distributions. To install the latest version:
sudo apt update sudo apt install perl
To check if Perl is installed and find its version:
perl -v
CPAN (Comprehensive Perl Archive Network) is a repository of Perl modules. Once Perl is installed, you can use the CPAN tool to install Perl modules.
Open a terminal or command prompt.
If it's your first time using CPAN on the machine, you might want to run:
cpan
And then at the cpan prompt:
install Bundle::CPAN
To install a module:
cpan Module::Name
This environment variable can be used to specify additional directories to search for Perl modules before looking in the standard library and the directories specified in @INC
.
For example, if you have modules in the directory /home/user/perlmods
, you can set the variable like this:
On UNIX-like systems:
export PERL5LIB=/home/user/perlmods:$PERL5LIB
On Windows (using Command Prompt):
set PERL5LIB=C:\path\to\perlmods;%PERL5LIB%
Ensure the path to the Perl binary is in your system's PATH variable so you can run Perl scripts without specifying the full path.
Create a new file with the .pl
extension, e.g., test.pl
.
Add the following lines:
#!/usr/bin/perl use strict; use warnings; print "Hello, Perl!\n";
To run the script:
On UNIX-like systems:
chmod +x test.pl ./test.pl
On Windows:
perl test.pl
You should see the output Hello, Perl!
.
You've installed Perl, set up the environment, and learned how to run a Perl script. With Perl and CPAN, you have a powerful programming language and a vast library of modules at your disposal. Happy coding!
Perl environment variables configuration:
PERL5LIB
for additional library paths and PATH
for Perl executable..bashrc
or .bash_profile
file:export PERL5LIB=/path/to/lib export PATH=$PATH:/path/to/perl/bin
CPAN installation and usage in Perl:
cpan
.cpan Module::Name
Perl version management tools:
plenv
or perlbrew
enable managing multiple Perl versions on the same machine.plenv
:git clone https://github.com/tokuhirom/plenv.git ~/.plenv echo 'export PATH="$HOME/.plenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(plenv init --no-rehash -)"' >> ~/.bashrc source ~/.bashrc
Perl IDE installation and setup:
cpan Padre
Managing Perl modules and dependencies:
cpanm
to manage Perl modules and their dependencies.cpanm
:cpan App::cpanminus
cpanm Module::Name
Perl PATH configuration in [your operating system]:
.bashrc
or .bash_profile
file:export PATH=$PATH:/path/to/perl/bin