When provided with requirements at the level of subroutine functionality, a student completing this course will be able to implement Perl scripts and modules using regular expressions, references and unit tests. They will also have experience installing CPAN modules for further functionality.
This is demonstrated through the implementation of a command-line search engine.
This course only assumes the student is capable of working on the Bash command-line interface via ssh. There is also a fast track for students with experience in another programming language such as C, C++, Java, PHP, Visual Basic, Python or Ruby.
Topic 1: Scalars and the Perl Language
Creating Perl scripts; the difference between modules and pragma; Scalar variables; the strict and warnings pragma; numbers of different bases; numbers and strings – and casting between the two; string operators – concatenation and repetition; strings and variable interpolation; backquotes; backslash; general string delimiters.
Topic 2: Arrays and Lists
lists, arrays and their relationship; scalar applied to lists and arrays; undefinedness; list delimiters; joining lists into strings; merging lists; push, pop, shift and unshift; lexical and numerical sort; list range operators; map and grep.
Topic 3: Control Flow and Conditionals
boolean values – defined, undefined, truth and falsehood; Boolean operators – && and || or not!; feature “switch” and implicit variables (and a warning not to use them); for each, for, if, unless, while, next, last, redo … until; ternary operators; blocks, lexical variables and global variables.
Topic 4: Hashes and Lists
creation of hashes using single value, list and fat comma assignment; deletion of a key-value pair; the difference between false, undefined and non-existent values; duplicate keys in list hash assignment; the %ENV hash
Topic 5: Subroutines
definition and invocation of subroutines; state variable declaration; variable scope; various ways of passing parameters to a subroutine; returning arrays and hashes; passing a hash into a subroutine; using and understanding want array
Topic 6: References
references to arrays, hashes, scalars and subroutines; passing references to subroutines and returning them as values; using sort with the developer’s own comparison subroutine; various approaches to passing named parameters to a subroutine; use of the ‘ref’ operator
Topic 7: Data I/O, CLI and Regex matching
regex matching and substitution; reading from a file; split and join; greedy vs non-greedy pattern matching; the use of the \L, \U and \E string operators; Perl’s grep and regular expressions; using Getopt:Long for a CLI
Topic 8: Modules and Unit tests
Perl distributions and the directory structure; the @INC array; package inheritance with ‘use parent’; CSV parsing; using OO Perl packages; unit testing; using web services; using Exporter to export functions.