Perl Cheatsheet

Testing, Debugging, and Ecosystem

Use this Perl reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

Test::More

use Test::More;

is add(2, 3), 5, 'adds two numbers';
ok defined $value, 'value is present';
is_deeply [sort @names], ['Ada', 'Grace'], 'names match';

done_testing;

Test::More is the standard testing base. Use is for scalar equality, ok for truth checks, and is_deeply for nested data.

Running Tests

prove -l t
prove -lv t/parser.t
perl -Ilib t/parser.t

The -l flag adds lib/ to @INC. prove discovers and runs .t files and reports TAP output.

Debugging

perl -d script.pl
perl -MData::Dumper -E 'say Dumper({a=>1})'
use Data::Dumper;
warn Dumper($value);

Use warnings and small repro scripts first. For larger programs, the built-in debugger and structured logging are better than scattered prints.

Ecosystem Anchors

NameRole
MetaCPAN (metacpan.org)search and documentation hub for all CPAN modules
perlbrew / plenvper-user Perl version managers, leave system Perl alone
local::libinstall CPAN modules into your home dir without root
cpanm / Cartonlightweight installer / dependency lockfile
DBI + DBD::Pg, DBD::SQLite, DBD::mysqlthe database interface and its drivers
Mojolicious / Dancer2the mainstream web frameworks
Perl::Critic / perltidylinting and formatting

CPAN Clients

cpanm Module::Name
cpan Module::Name
carton install
perlbrew install perl-5.40.0 && perlbrew switch perl-5.40.0
cpanm --local-lib=~/perl5 Module::Name   # local::lib style install

cpanm is a common lightweight installer. carton can lock dependency versions for applications.

Project Layout

my-app/
  cpanfile
  lib/My/App.pm
  script/my-app
  t/basic.t

Put reusable code under lib/, executable scripts under script/, and tests under t/.

cpanfile

requires 'JSON::MaybeXS', '1.004000';
requires 'DBI';
on test => sub {
    requires 'Test::More';
};

A cpanfile declares dependencies without tying the project to one installer.

Perl::Critic and Formatting

perlcritic lib script
perltidy -b script/my-app

Style tools help teams stay consistent. Apply rules pragmatically; old Perl codebases may use local conventions.

Taint and Security Note

Perl has taint mode for some security-sensitive scripts, but modern application security still requires validation, output escaping, safe file paths, least privilege, and parameterized database queries.