Perl Internals, History, Raku and Best Practices

53.1 How Perl Runs

Explore with perl -MO=Concise,-exec -e 'print 1+2' (the op tree; constant folding), perl -MO=Deparse script.pl (see how Perl parsed your code), Devel::Peek (SV internals).

Memory is managed by reference counting (deterministic destruction; cycles leak unless weakened).

Hash randomization (since 5.18) and the PERL_HASH_SEED environment variable.

Source → Lexer/Parser (toke.c, perly.y) → Op tree (compile phase) → Peephole optimizer → Runloop executes ops (run phase)
Data: SV (scalar), AV (array), HV (hash), CV (code), GV (glob), IO; reference counting for memory management

53.2 Version History Highlights

Larry Wall's first release "Camel book" era References, modules, OOP, lexical my; the basis of modern Perl

our, Unicode beginnings, lexical warnings Solid Unicode, PerlIO layers, ithreads

say, state, //, named captures, recursive regex Yearly releases begin, package NAME {}, s///r, __SUB__, fc, hash randomization

Experimental signatures, postfix deref, key/value slices <<>>, /n, indented heredocs, . removed from @INC

Unicode updates, isa operator, chained comparisons try/catch (experimental), 0o octal

Stable signatures, use v5.36 bundle, builtin, defer, multi-variable for, isa stable

class feature (experimental), //=/||= signature defaults, optional 1; at module end, smartmatch deprecated

try/catch stable, builtin stable (true/false/trim/...), __CLASS__, :reader, ^^ logical xor

Continued class improvements and new experimental features (check perl5420delta)

Perl 7 was announced in 2020 as "5.32 with modern defaults" but was put on hold. The use v5.36+ bundles now deliver modern defaults. The Perl Steering Council governs development.

Raku (formerly Perl 6, renamed in 2019) is a separate language: gradual typing, grammars, junctions, built-in concurrency, and the Rakudo compiler. It's not a replacement for Perl 5.

53.3 Perl Best Practices

Style and safety ✅ Start every file with use v5.36; (or use strict; use warnings; on older Perls).

✅ Use lexical variables (my), lexical filehandles, three-argument open, and check errors (or die / autodie).

✅ Use signatures, named arguments for more than ~3 parameters, and // for defaults.

✅ Use meaningful names, perltidy for formatting, and perlcritic (severity 3–4) in CI.

✅ Use /x for complex regexes, with comments. Use qr// for reuse.

✅ Keep subs short. Return explicitly. Avoid modifying @_ and $_ unexpectedly.

✅ Use placeholders for SQL, list-form system, and taint mode for privileged scripts.

✅ Write tests (t/), POD documentation, and pin dependencies (Carton).

✅ Prefer Moo (or the core class/Object::Pad) for OOP. Use roles over deep inheritance.

❌ Bareword filehandles (open FH, ...) and two-argument open

❌ Global variables, symbolic references, string eval with external data

❌ given/when and smartmatch (deprecated), indirect object syntax (new Foo), &sub calls without reason

❌ Parsing CSV/HTML/JSON with regex (use the right module) ❌ Overly clever one-liners in maintained code ("write-only Perl")

❌ Prototypes for argument checking (they don't do that; use signatures)