Running Modern Perl
Learn how to run code written in Modern Perl.
We'll cover the following
Basic program skeleton
The Modern::Perl
module from the
#!/usr/bin/env perluse Modern::Perl '2020';use autodie;
If you don’t have Modern::Perl
installed, you could write the following code instead:
#!/usr/bin/env perluse 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:
##!/usr/bin/env perluse Modern::Perl;use Test::More;# example code heredone_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.