Installation, Tools and First Program
2.1 Installing Perl
perl -v # most Unix/macOS systems already have Perl
# Linux
sudo apt install perl perl-doc cpanminus # Debian/Ubuntu
sudo dnf install perl perl-App-cpanminus # Fedora/RHEL
# macOS
brew install perl
# Windows: Strawberry Perl (strawberryperl.com), includes a compiler toolchain and cpan
# Per-user Perl versions (recommended for development; don't touch the system Perl)
curl -L https://install.perlbrew.pl | bash
perlbrew install perl-5.40.0 && perlbrew switch perl-5.40.0
perlbrew install-cpanm
# Alternative: plenv (like rbenv/pyenv)2.2 Hello, World
#!/usr/bin/env perl
use v5.36; # enables strict, warnings, say, signatures, and more
say "Hello, World!";
my $name = "Perl";
say "Hello, $name!"; # interpolation in double quotes
say 'No $interpolation here';perl hello.pl
chmod +x hello.pl && ./hello.pl
perl -e 'print "Hello from a one-liner\n"'
perl -E 'say "Hello with say"' # -E enables all features, including say2.3 Essential Command-Line Switches
-e 'code' / -E 'code' Execute code (-E enables the newest features) Syntax check only Enable warnings / all warnings Wrap the code in while (<>) {... }
Like -n, but prints $_ after each line Edit files in place (with an optional backup) Auto-chomp input and add \n to print
Autosplit lines into @F (with a custom separator via -F) Load a module (-MData::Dumper) Add to the module search path (@INC) Run under the debugger Taint mode (security)
Skip leading garbage until a #!perl line Set the input record separator (-0777 slurps whole files) Rudimentary switch parsing for scripts Show configuration (perl -V:archname)
2.4 Documentation: perldoc
perldoc perl # overview of all documentation
perldoc perlintro # quick introduction
perldoc perlfunc # all built-in functions
perldoc -f split # docs for one function
perldoc -v '$_' # docs for a special variable
perldoc -q "sort a hash" # search the FAQ
perldoc perlre # regular expressions
perldoc List::Util # module documentation
perldoc -l List::Util # where the module is installed2.5 Comments and Basic Syntax Rules
Statements end with ;. Blocks use { }. Whitespace is mostly insignificant.
Variables have sigils: $ (scalar), @ (array), % (hash), & (subroutine), * (typeglob).
The script ends at the end of the file, or at __END__ / __DATA__ (text after __DATA__ can be read via the DATA filehandle).
# Single-line comment
=pod
Multi-line comments are usually written as POD blocks.
=cut2.6 Editors and Tooling
VS Code + the "Perl Navigator" extension (LSP: syntax checking, perlcritic, perltidy, navigation)
perltidy (formatter), perlcritic (linter based on *Perl Best Practices*), Perl::LanguageServer, Devel::NYTProf (profiler), Data::Printer (p $var)
REPLs: perl -de0 (the debugger as a REPL), Reply, Devel::REPL