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
- 01Your first PerlNot started
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.
- 02Scalars, strings and the my keywordNot started
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.
- 03Arrays: ordered lists of valuesNot started
Holding many values under one name, reaching into the list by position, and the few functions that add, remove, join and slice items.
- 04Hashes: looking values up by nameNot started
Storing values under names instead of positions, counting things as you meet them, and why printing a hash always starts by sorting its keys.
- 05Decisions, and the == against eq trapNot started
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.
- 06Loops: while, foreach and rangesNot started
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.
- 07Subroutines: naming a piece of workNot started
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.
- 08Context: one value or a whole listNot started
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.
- 09Patterns: matching, replacing and splitting textNot started
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.
- 10map, grep and sortingNot started
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.
- 11References: names for bigger dataNot started
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.
- 12Capstone: a report from a tableNot started
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.
