Course

Perl from the ground up

The language that made text processing a one-liner

  • Beginner
  • 12 chapters
  • 215 min read

Learn Perl by writing it: printing and quoting, scalars named with my, arrays and hashes, decisions and the difference between numeric and text comparison, loops over lists and ranges, subroutines and their argument list, context, pattern matching with captures and substitutions, map and grep, sorting with a comparator block, and references used to build records — ending with a report assembled from a table.

What You'll Learn

  • Print a line with print, and shape one with printf
  • Name values with my, fill them into double-quoted text, and glue text with a dot
  • Keep a list in an array, and add, remove, join and slice it
  • Look values up by name in a hash, tally with it, and always sort the keys to print
  • Branch with if, elsif and else, and know why numbers use one comparison and text another
  • Repeat work with while and foreach over lists and ranges, and steer it with next and last
  • Write subroutines that read their arguments, return a value, and answer with several at once
  • Tell scalar context from list context, and ask for the one you meant
  • Match, capture, substitute, split and join text with patterns
  • Change every item with map, keep what you want with grep, and sort with a comparator block
  • Build records as hash references, and keep them in one list
  • Filter a table, sort it by a field, and print a report with printf

Prerequisites

  • No programming experience needed — this course starts at the first line
  • Knowing any other language will make the early chapters quick

Course Content

  1. 01
    Your first Perl

    What Perl is, how to print a line, why every file here starts with two strictness lines, and the text every program after this one is built from.

    Beginner · 14 min read

    Not started
  2. 02
    Scalars, strings and the my keyword

    Naming a value with my, the arithmetic you expect from numbers, gluing text with a dot, and the two kinds of quotes — one that fills values in and one that does not.

    Beginner · 15 min read

    Not started
  3. 03
    Arrays: ordered lists of values

    Holding many values under one name, reaching into the list by position, and the few functions that add, remove, join and slice items.

    Beginner · 16 min read

    Not started
  4. 04
    Hashes: looking values up by name

    Storing values under names instead of positions, counting things as you meet them, and why printing a hash always starts by sorting its keys.

    Beginner · 17 min read

    Not started
  5. 05
    Decisions, and the == against eq trap

    If, elsif and else, the unless that reads backwards on purpose, what Perl treats as false, and the two sets of comparison operators that must not be mixed up.

    Intermediate · 17 min read

    Not started
  6. 06
    Loops: while, foreach and ranges

    Repeating work over a list or a range, the loop that reads like a sentence, the variable Perl offers you for free, and how to leave a loop early.

    Intermediate · 17 min read

    Not started
  7. 07
    Subroutines: naming a piece of work

    Defining your own named pieces of work, where the arguments arrive, why a subroutine can be called before it is defined, and how one answers with several values.

    Intermediate · 18 min read

    Not started
  8. 08
    Context: one value or a whole list

    The idea that quietly shapes every Perl expression: the same code can mean one value or a whole list, and knowing which one you asked for explains most surprises.

    Intermediate · 18 min read

    Not started
  9. 09
    Patterns: matching, replacing and splitting text

    The part of Perl that made its name: searching inside a string, pulling pieces out of it with captures, rewriting it, and cutting it into fields.

    Advanced · 20 min read

    Not started
  10. 10
    map, grep and sorting

    Turning a loop into a single line: changing every item, keeping the ones a condition likes, and putting a list in the order you actually asked for.

    Advanced · 20 min read

    Not started
  11. 11
    References: names for bigger data

    A reference is one value that points at a list or a hash, which is how a record is built in Perl — and how a list of records is built from it.

    Advanced · 21 min read

    Not started
  12. 12
    Capstone: a report from a table

    Everything at once: a small table kept in the file, cut into records, filtered, sorted by a field, and printed as a report whose columns line up.

    Advanced · 22 min read

    Not started