Perl Fundamentals
Perl is a general-purpose programming language built for text processing, system administration, and gluing other programs and data formats together. It reads and rewrites files, drives command-line one-liners, and powers long-running scripts and web backends. It exists to make everyday data-wrangling and automation tasks quick to write, with regular expressions, file handling, and process control built into the core language rather than added by libraries.
itProgramming languages | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic - Perl Fundamentals
Perl is a programming language that Larry Wall built in 1987 to do the
unglamorous work of computing: reading text, rewriting text, moving data
between formats that were never meant to meet, and holding other programs
together with string and tape. The corridor version is that Perl took the
best parts of the Unix toolbox, awk, sed, the shell, a bit of C, and put
them in one place so you did not have to wire six tools together to produce
one report.
First, a naming hazard, because it trips everyone. When people say Perl, they mean Perl 5, currently version 5.44, developed continuously since 1994. There was a separate project called Perl 6 that began in 2000, grew into its own language, and was renamed Raku in 2019. A "Perl 7" was announced in 2020 and quietly set aside in 2021. So Perl means Perl 5, and if a tutorial talks about Perl 6, it is talking about a different language entirely.
Three ideas carry most of the language. The first is sigils: every
variable starts with a punctuation mark that says what it is. $ for a single
value, @ for a list, % for a set of key-value pairs. The second is
context: every expression runs in either list or scalar context, decided
entirely by what surrounds it, and the same array gives you its contents in
one and its length in the other. The third is references, which are the
only way to build a data structure with any depth, because plain Perl lists
flatten themselves flat the moment you nest them.
The thing that will surprise you is that Perl mostly does not stop you when
something goes wrong. open a file that is not there and Perl returns a quiet
false and carries on; your reads just produce nothing. This is why almost
every Perl program opens with use strict; and use warnings;, which turn a
pile of silent mistakes into loud ones, and why experienced Perl checks the
result of every open and system. The language you hear people complain
about is the one written without those lines. The language that is genuinely
pleasant to maintain is a subset you choose by opting in.
The other surprise is the size of the safety net around it. CPAN, the
module archive that has been running since 1995, holds roughly 47,000
packages, which is the real reason Perl programs stay short: someone has
already written and tested the JSON parser, the date handler, the database
layer. You install from it with cpanm and pin versions with a cpanfile.
Where to go next. The Cheatsheet puts sigils, context, the regex
operators, and the command-line switches on one page. Practice walks the
perl, perldoc, cpanm, and prove commands with the reasoning for each.
Field Notes is where people who maintain production Perl tell you what
actually costs time. Timeline explains how a 1987 report-printing tool
became the language it is now, which makes a lot of its quirks make sense.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://www.perl.org/
Supports
- Perl's identity as a feature-rich general-purpose language in development since 1987
- Current stable release is Perl 5.44
- Perl today meaning Perl 5, not Perl 6 or Raku
- Reference-path rationale for perl.org
- https://perldoc.perl.org/perlintro
Supports
- Perl as a general-purpose language for text manipulation, system administration, web, and network work
- Scalars, arrays, hashes and their sigils; single elements taking the $ sigil
- The default variable $_ and its use by many built-ins
- use strict and use warnings at the top of a program; use v5.xx feature bundles
- my for lexically scoped variables
- References as scalars pointing to other data; the arrow operator
- Subroutines with sub, arguments in @_, explicit return
- Regex via // and =~, s/// substitution, metacharacters and quantifiers
- Running programs with perl progname.pl and the shebang line
- perlintro reference-path rationale
- https://perldoc.perl.org/perl
Supports
- Existence and grouping of the core manual pages (tutorials, references, guides)
- perldoc perl documentation-index reference-path rationale
- https://perldoc.perl.org/perlrun
Supports
- Switch behavior for -e, -E, -n, -p, -i, -a, -F, -l, -M, -w, -T, -c, -d, -0
- -n wraps code in while (<>) without printing; -p adds an automatic print
- -i edits in place, keeping a backup when given a suffix
- -a autosplit into @F; -F sets the separator and implies -a -n
- -0777 sets the input record separator so the diamond returns the whole file
- use strict / use warnings effect summary
- perlrun reference-path rationale and multiple quiz answers (in-place edit, whole-file slurp, one-liners)
- https://perldoc.perl.org/perlreftut
Supports
- References as the mechanism for nested data structures
- Taking references with backslash and creating anonymous data with [ ] and { }
- perlreftut reference-path rationale and the reference quiz answer
- https://perldoc.perl.org/perlref
Supports
- Reference creation, dereferencing syntax, ref() return values, autovivification
- Postfix dereference syntax
- https://perldoc.perl.org/perlre
Supports
- Regex modifiers g, i, m, s, x, r, e and their meaning
- Named captures, lookahead and lookbehind, non-greedy quantifiers
- perlre reference-path rationale
- https://perldoc.perl.org/perlretut
Supports
- Introductory treatment of matching, capturing, and substitution
- Regex binding-operator quiz answer
- https://perldoc.perl.org/perlootut
Supports
- A class is a package, a method is a subroutine, an object is a blessed reference
- Inheritance via @ISA, usually through use parent
- The recommendation to use a CPAN object system; Moose, Moo, Class::Tiny positioning
- perlootut reference-path rationale and the bless quiz answer
- https://perldoc.perl.org/perlobj
Supports
- bless associating a reference with a package; method dispatch through that package
- isa and can; use parent for setting inheritance
- https://perldoc.perl.org/perlvar
Supports
- Meaning of $_, @_, $0, @ARGV, %ENV, $/, $\, $,, $", $!, $@, $?, $., @INC, %INC
- wantarray reporting list, scalar, or void context
- https://perldoc.perl.org/perlstyle
Supports
- Core guidance on readable Perl naming and layout
- perlstyle reference-path rationale
- https://perldoc.perl.org/functions/open
Supports
- open returning false and setting $! on failure rather than dying
- Three-argument open forms for read, write, append, and encoding layers
- The unchecked-open quiz answer and the Field Notes mistake card
- https://perldoc.perl.org/functions/return
Supports
- return yielding a value that depends on the caller's context
- return undef producing a one-element list in list context; bare return idiom
- The return-undef quiz answer
- https://perldoc.perl.org/functions/wantarray
Supports
- wantarray as the way a subroutine detects its calling context
- Context affecting return values
- https://perldoc.perl.org/autodie
Supports
- use autodie converting failed built-ins such as open into exceptions
- The autodie quiz answer and Field Notes mistake card
- https://perldoc.perl.org/feature
Supports
- Feature bundles enabled by use VERSION (use v5.36 enabling strict, warnings, signatures, say)
- The class feature available since 5.38 and still experimental
- try/catch as a feature; multi-value for loop
- The backward-compatibility and feature-bundle quiz answer
- https://perldoc.perl.org/perlhist
Supports
- Perl 1.0 released 1987-12-18; Perl 4.0 1991-03-21; Perl 5.000 1994-10-17
- Perl 5.004 1997-05-15; Perl 5.6.0 2000-03-22; Perl 5.8.0 2002-07-18; Perl 5.10.0 2007-12-18
- Perl 5.26.0 2017-05-30; Perl 5.36.0 2022-05-27; Perl 5.38.0 2023-07-02; Perl 5.40.0 2024-06-09
- The pumpking release-manager role and the move to a regular release cadence
- Timeline events for each release
- https://perldoc.perl.org/perl5260delta
Supports
- Perl 5.26 removed the current directory (".") from @INC by default as a security change
- Timeline event and Field Notes shift card
- https://perldoc.perl.org/perl5360delta
Supports
- Perl 5.36 made subroutine signatures stable and shipped the use v5.36 bundle
- Timeline event
- https://perldoc.perl.org/perl5400delta
Supports
- Perl 5.40 made try/catch and the multi-value for loop non-experimental
- Timeline event
- https://en.wikipedia.org/wiki/Perl
Supports
- Larry Wall created Perl, first released 1987; influences from awk, sed, C, and the Unix shell
- Perl 5 (1994) introduced references, lexical variables, and modules
- CPAN established 1995; Perl 5.004 and CGI.pm accelerating web adoption
- Perl 6 announced 2000; renamed Raku 2019; Perl 7 announced 2020 and later shelved
- TMTOWTDI and "easy things easy, hard things possible" design slogans
- Uses: text processing, system administration, web, network programming, bioinformatics, glue code
- Timeline events for early history and the redesign announcement
- https://en.wikipedia.org/wiki/Raku_(programming_language)
Supports
- First official Perl 6 release (Rakudo "Christmas") on 2015-12-25
- Perl 6 renamed to Raku in October 2019
- Raku being a separate language that does not run Perl 5 code
- Timeline events for the split; Landscape placement for Raku
- https://www.cpan.org/
Supports
- CPAN online since October 1995
- Roughly 47,000 distributions from about 14,000 authors
- metacpan.org as the search interface
- CPAN launch timeline event and the CPAN quiz answer
- https://metacpan.org/
Supports
- MetaCPAN as the CPAN search and documentation interface, showing dependencies, test results, and release activity
- Reference-path rationale
- https://metacpan.org/pod/App::cpanminus
Supports
- cpanm as a zero-configuration CPAN installer, the -L flag for local installs, and --installdeps for a cpanfile
- The dependency-isolation quiz answer and reference-path rationale
- https://metacpan.org/pod/Carton
Supports
- Carton freezing exact module versions in a snapshot and running a program against them
- The dependency-isolation quiz answer, Field Notes tradeoff card, and Awesome Links rationale
- https://metacpan.org/pod/Moo
Supports
- Moo as a lightweight class builder with accessors, constructors, and roles
- OO-systems positioning; Awesome Links rationale
- https://metacpan.org/pod/Moose
Supports
- Moose as the full Perl object system with a type system, roles, and introspection
- OO-systems positioning; Awesome Links rationale
- https://metacpan.org/pod/DBIx::Class
Supports
- DBIx::Class as an object-relational mapper built on DBI
- Awesome Links rationale
- https://plackperl.org/
Supports
- PSGI as the calling convention between Perl web apps and servers; Plack as its toolkit and middleware
- Awesome Links rationale
- https://metacpan.org/pod/Starman
Supports
- Starman as a preforking PSGI application server used in production behind a reverse proxy
- Awesome Links rationale
- https://metacpan.org/pod/Perl::Critic
Supports
- Perl::Critic as a configurable static analyzer for risky or non-idiomatic constructs
- Awesome Links rationale
- https://metacpan.org/pod/Devel::NYTProf
Supports
- Devel::NYTProf as the standard line-level and subroutine profiler with HTML reports
- Awesome Links rationale
- https://metacpan.org/pod/IO::Async
Supports
- IO::Async as an event-driven framework for non-blocking network and process work
- Awesome Links rationale
- https://metacpan.org/pod/Cpanel::JSON::XS
Supports
- Cpanel::JSON::XS as a fast C-backed JSON encoder and decoder
- Awesome Links rationale
- https://metacpan.org/pod/Perl::Tidy
Supports
- Perl::Tidy as an automatic code formatter for Perl
- Awesome Links rationale
- https://gist.github.com/Grinnz/be5db6b1d54b22d8e21c975d68d7a54f
Supports
- Perl 7 announced in 2020 by pumpking Sawyer X, planned as Perl 5.32 with modern defaults
- The plan set aside in 2021 in favor of the use VERSION feature-bundle mechanism
- Timeline events for the Perl 7 announcement and withdrawal; the release-model quiz answer; Field Notes shift card
- https://blogs.perl.org/users/psc/2022/05/what-happened-to-perl-7.html
Supports
- The Perl Steering Council's account of setting aside the changed-defaults Perl 7 plan
- Timeline event for the Perl 7 withdrawal
- https://www.perl.com/article/what-is-new-in-perl/
Supports
- Perl 5.40 (2024-06-09) features: __CLASS__, :reader field attribute, try/catch and multi-value for no longer experimental, ^^ operator, spaced -M
- Timeline event for 5.40
- https://www.perl.com/
Supports
- Perl.com as the community magazine with per-release "what is new" articles
- Reference-path rationale
- https://learn.perl.org/
Supports
- learn.perl.org as a curated index of beginner material and per-OS installation guides
- Reference-path rationale
- https://www.modernperlbooks.com/books/modern_perl_2016/
Supports
- Modern Perl (chromatic) as a freely readable book teaching current Perl 5 practice
- Reference-path rationale
- https://perlmaven.com/perl-tutorial
Supports
- Perl Maven as an example-driven tutorial series covering context, references, and file handling
- Reference-path rationale
- https://perlmaven.com/scalar-and-list-context-in-perl
Supports
- An array in scalar context yielding its element count; list context yielding elements
- The scalar-vs-list context quiz answer and Field Notes difficulty card
- https://blogs.perl.org/users/aristotle/2017/11/perl5-refs-flattening.html
Supports
- Perl lists flattening within a larger list; references as the way to prevent it
- The list-flattening quiz answer
- https://dev.to/szabgab/perl-weekly-715-why-do-companies-move-away-from-perl-ja6
Supports
- Companies leaving Perl citing developer shortage and unwillingness to learn it
- CPAN modules with long-standing bugs and no new releases as an ecosystem concern
- Field Notes tradeoff card
- https://www.beatworm.co.uk/blog/computers/perls-decline-was-cultural-not-technical
Supports
- Perl 6 as a symptom of community fragmentation; TMTOWTDI externalizing innovation to CPAN
- The lack of a single opinionated framework compared with Ruby on Rails
- Context for the Field Notes tradeoff and shift cards
- https://www.python.org/
Supports
- Python as the language most new scripting and glue work goes to instead of Perl; Landscape placement
- https://www.ruby-lang.org/
Supports
- Ruby as a Perl-influenced language competing for scripting and internal tooling; Landscape placement
- https://www.php.net/
Supports
- PHP as what much of the Perl CGI web tier became; Landscape placement
- https://raku.org/
Supports
- Raku as the renamed Perl 6, a separate language that does not run Perl 5 code; Landscape placement
- https://www.gnu.org/software/gawk/
Supports
- AWK as the field-splitting pattern-action language Perl's -a and -F reproduce; Landscape placement
- https://www.gnu.org/software/sed/
Supports
- sed as the stream editor Perl's s/// and -p mode were built to match; Landscape placement
- https://www.gnu.org/software/bash/
Supports
- Bash as the shell Perl scripts replace once shell logic grows complex; Landscape placement
- https://learn.microsoft.com/en-us/powershell/
Supports
- PowerShell as the object-pipeline automation shell on Windows, cross-platform since version 6; Landscape placement
- https://go.dev/
Supports
- Go as a compiled language chosen for concurrent services Perl's per-process model handles poorly; Landscape placement
- https://nodejs.org/
Supports
- Node.js as an event-loop runtime named alongside Go for high-connection services; Landscape placement
- https://strawberryperl.com/
Supports
- Strawberry Perl as the standard Windows Perl 5 distribution bundling a compiler toolchain and cpan; Landscape placement
- https://www.activestate.com/perl
Supports
- ActiveState Perl as a commercially packaged distribution with prebuilt modules and paid support; Landscape placement
- https://mojolicious.org/
Supports
- Mojolicious as a modern dependency-light Perl web framework with a built-in async event loop; Awesome Links rationale
- https://perldancer.org/
Supports
- Dancer2 as a lightweight route-based Perl web framework; Awesome Links rationale
- https://github.com/hachiojipm/awesome-perl
Supports
- Community-curated index used to select the Awesome Links entries
- https://perldoc.perl.org/perlintro
Supports
- All infographic labels, tables, and captions restate the course cheatsheet, slides, and intro
