Running Modern Perl

Learn how to run code written in Modern Perl.

Basic program skeleton

The Modern::Perl module from the Comprehensive Perl Archive NetworkModern Perl programming relies on the CPAN (http://www.cpan.org/). The Comprehensive Perl Archive Network is an uploading and mirroring system for redistributable, reusable Perl code. (CPAN) tells Perl to warn us about typos and other potential problems. It also enables new features introduced in Modern Perl releases. We've already set up Modern Perl for all the code playgrounds in this course. If you're running the code locally, you can start with this basic program skeleton:

Press + to interact
#!/usr/bin/env perl
use Modern::Perl '2020';
use autodie;


If you don’t have Modern::Perl installed, you could write the following code instead:

Press + to interact
#!/usr/bin/env perl
use 5.30.0; # implies "use strict;"
use warnings;
use autodie;


Some examples use testing functions such as ok(), like(), and is(). The skeleton for these examples is shown here:

Press + to interact
##!/usr/bin/env perl
use Modern::Perl;
use Test::More;
# example code here
done_testing();

Note: We'll learn how to use these testing functions later on in this course.

Versions of Perl

The examples in this course work best with Perl 5.16.0 or newer, though we recommend using at least Perl 5.20. While the term Modern Perl has traditionally referred to any version of Perl from 5.10.1 on, the language has improved dramatically over the past several years.

Installing Perl

Although Perl comes preinstalled on many operating systems, we may need to install a more modern version. Windows users can download Strawberry Perl or ActivePerl. Users of other operating systems with Perl already installed (and a C compiler and the other development tools), can start by installing the CPAN module App::perlbrew.

Multiple Perl installations

The perlbrew tool manages multiple Perl installations, so we can switch between versions for testing and deployment. We can also install CPAN modules in our home directory without affecting the system installation. If you’ve ever had to beg a system administrator for permission to install software, you’ll appreciate this.