Skip to content
LumenaryAcademy

Lumenary CS · Programming languages

Perl

The text-processing language that holds much of the Unix world together, from a first script to regular expressions, references, objects, tests and a complete log analyser.

Perl is a general-purpose scripting language created by Larry Wall in 1987 to make report-writing and text-wrangling on Unix easy. It became the glue of the early web and of system administration, and it is still installed on almost every Linux and macOS machine. Today you meet it in system scripts and build tools, in bioinformatics pipelines, in long-lived web applications, and anywhere people need to tear through text quickly. Its regular expressions were so good that most other languages copied them. Perl 5 is the language this course teaches; its sibling Raku (once called Perl 6) is a separate language.

This course is for anyone who already knows what a variable, a loop and a function are: the Start level of Lumenary CS or equivalent experience in any language. It begins with Perl's history and your first scripts, works through scalars, arrays and hashes and the idea of context, subroutines, references and nested data, regular expressions in depth, and files and text, and ends with modules and CPAN, object-oriented Perl, testing with Test::More, and a complete log analyser.

To run the code you need a perl command. On Linux and macOS it is almost certainly installed already (perl -v tells you which version); perl.org/get.html lists the official ways to get a newer one, including Strawberry Perl for Windows and perlbrew for managing several versions. There is no official online playground. Every complete program in these lessons was run with Perl 5.34 by Lumenary's test suite, and the output shown is the output it printed; each program also runs unchanged on newer releases, and the lessons point out what Perl 5.36 and later add. The lessons were drafted with AI assistance and are awaiting review by a human computer scientist.

AI-draftedAwaiting review by a computer scientist
  • Chloe · The Designer
    “Why is the language built this way?”
  • Margaret · The Profiler
    “What does it print, and what does it cost?”
  • Gideon · The Language Lawyer
    “What exactly does the language guarantee?”

Foundations · 3 lessons

Foundations

Run your first scripts with strict and warnings on, then learn Perl's three kinds of variable and their sigils, the idea of context, control flow, and subroutines.

  1. 1Getting started with PerlWhere Perl came from, where it still runs, and your first scripts with strict and warnings switched on. 45 min
  2. 2Scalars, arrays and hashesPerl's three kinds of variable, the sigils that mark them, and context, the idea that makes Perl read like Perl. 55 min
  3. 3Control flow and subroutinesConditions, loops and statement modifiers, then subroutines from the classic @_ style to modern signatures. 55 min

Practice · 3 lessons

Practice

Build nested data with references, master regular expressions, Perl's great strength, and read, transform and write files while handling errors properly.

  1. 4References and nested data structuresHow one scalar can point at an array, a hash or a subroutine, and how that lets you build records, tables, trees, closures and dispatch tables. 60 min
  2. 5Regular expressionsPerl's great strength in depth, from matching and captures to substitution, global matching, lookaround, and knowing when not to use a regex. 70 min
  3. 6Files, text and errorsReading and writing files safely, handling Unicode text correctly, and reporting and catching errors with die, eval and try. 60 min

Professional · 2 lessons

Professional

Organise code into modules, use CPAN, write object-oriented Perl, test it with Test::More, and build a complete log analyser the way working Perl programmers do.

  1. 7Modules, CPAN and objectsPackages and modules, installing from CPAN with cpanm, and object-oriented Perl from bless to Moo and the new class syntax. 65 min
  2. 8Testing, tools and a log analyserTest::More and prove, the tools Perl professionals use every day, and a complete, tested command-line log analyser. 70 min

Further reading and resources

  • perl.orgThe official home of the Perl programming language: downloads, news, learning resources and community links.
  • Perl documentation (perldoc.perl.org)The complete official documentation for every Perl release: tutorials, the language reference, every built-in function and every core module.
  • perlsyn, perldata and perlopPerl has no separate standard: the perl interpreter defines the language, and these reference pages describe its syntax, data and operators.
  • MetaCPANSearch and read the documentation of the tens of thousands of modules on CPAN, the Comprehensive Perl Archive Network.
  • The Perl and Raku FoundationThe non-profit that supports the development of Perl and Raku.
  • RakuThe language formerly called Perl 6: a separate language with its own design, implementation and community.