- 01Setting up (what you'll need)
- 02Your first output (print)
- 03Variables (scalar variables, $)
- 04Branching (the if statement)
- 05Repeating (the for loop)
- 06Writing a subroutine (a function)
- 07Repeating (the while loop)
- 08Working with arrays (@)
- 09Working with hashes (%)
- 10Regular expression matching
- 11Substitution with regular expressions (s///)
- 12Working with strings
- 13References
- 14Anonymous subroutines
- 15File input and output, the basics
- 16Modules and use strict / warnings
- 17The ternary operator
- 18Sorting (sort)
- 19Packages and the basics of object orientation
- 20[Project] Build a small inventory system
Regular expression matching
This lesson covers pattern matching with regular expressions, the thing Perl is best known for.
Writing $string =~ /pattern/ tests whether a string matches a particular pattern. Perl's regular expressions are so capable that they became the model for the feature in many other languages.
The sample code does a rough email-format check with the regular expression $email =~ /^\w+@\w+\.\w+$/.
A common early stumble is remembering what the symbols mean. You pick them up gradually: \w is a letter or digit, + is one or more repetitions, ^ and $ are the start and end of the string.
In professional work, Perl's regular expressions are used heavily for pulling particular patterns out of log files and for validating input.
๐งช This site can't compile or run Perl directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
