Getting Started
🐪 Getting Started
📥 Installing Perl
Most Linux and macOS systems already have Perl installed — check with:
On Windows, Strawberry Perl is the standard distribution — a complete, self-contained installer including cpanm (Chapter-9-of-Course-2's package installer) out of the box.
▶️ Running a Perl Script
On Linux/macOS, a script can also be made directly executable, using a shebang line as its first line:
#!/usr/bin/env perl is preferred over a hardcoded path like #!/usr/bin/perl — env finds whichever perl is first on the system's PATH, working correctly across different installations rather than assuming one fixed location.
🛡️ use strict; use warnings; — Non-Negotiable Culture
Perl is famously permissive by default — variables can be used without being declared, typos in variable names silently create a new variable rather than raising an error, and genuinely dangerous constructs are allowed without complaint. This permissiveness is exactly where Perl's "write-only code" reputation comes from. The fix, and the actual convention in every real Perl codebase, is two lines at the top of every script:
With use strict; in place, that same typo raises Global symbol "$usr_name" requires explicit package name at compile time — before the script ever runs — turning a silent, confusing bug into an immediate, precise error pointing at the exact line. There is essentially no legitimate reason to omit use strict; use warnings; from a real script.
🖨️ print and say
print is the original, universal output function — but unlike console.log or Python's print(), it does not add a trailing newline; you write \n explicitly. say (available via use feature 'say';, or automatically with use v5.10; or later) behaves like print but appends the newline for you — the more ergonomic default for everyday scripts.
💬 Comments
POD (=pod ... =cut) is a distinctly Perl feature — a lightweight markup format for documentation, embeddable directly inside the same file as the code it documents, and extractable into HTML/man pages by standard tools. Ordinary # comments cover everything else.
Perl vs. Bash: Why Perl Exists
Perl was built specifically because Bash/sed/awk hit real limits once a script needs actual data structures, subroutines with proper scoping, or complex logic — Bash's "everything is a string" model gets unwieldy fast beyond simple pipelines. Perl keeps the same regex-heavy, text-processing instincts (Chapter 6 covers this directly) while adding real arrays, hashes, references, and subroutines on top — the reason it became the standard "glue language" for text-heavy scripting throughout the 1990s and 2000s, and still shows up constantly in legacy sysadmin and text-processing code today.
Shebang line
#!/usr/bin/env perl — makes a script directly executable.
use strict / use warnings
Mandatory in real code — catches typos and likely bugs at compile time.
print vs say
print needs an explicit \n; say adds one automatically.
Comments & POD
# for single lines; =pod/=cut for embedded documentation.
💻 Coding Challenges
Challenge 1: Your First Script
Write a script beginning with the correct shebang line and use strict; use warnings;, that prints "Hello, Perl!" using say.
Challenge 2: Catch the Typo
Given a short script with use strict; enabled that assigns to $message but then tries to print $mesage (missing an "s"), write down the exact compile-time error Perl would raise, and explain in one sentence why use strict is what causes an error here instead of silent wrong output.
Challenge 3: print vs say
Write two versions of a script that prints three separate lines — one using only print (correctly formatted with newlines), one using say — producing identical output.
🎯 What's Next
Next chapter: Scalars & Basic Data Types — the $ sigil, strings/numbers, string interpolation, and my/our/local scoping.