Perl Coding Practices
Application skill for Perl style learning (from the archived awesome-guidelines style capsules). When project adopts PBP/perltidy profile, follow that formatter config first.
Core Principle
Perl maintainability is lexical scope + checked I/O, strict warnings on, 3-arg open, explicit subs, avoid indirect objects and void map/grep.
When to Use / NOT
- Perl scripts,
.pm modules, CPAN-style distributions, Mojolicious/Dancer apps.
- Setting up perlcritic, perltidy, prove/t harness in CI.
NOT when:
- Raku (Perl 6), different language foundations.
- Generated
.pm stubs, validate generators.
Workflow
- Layout, indent, braces, alignment (
perl-style-formatting-layout.md).
- Scope, v5.36, my, naming (
perl-style-strict-scoping.md).
- Subs/I/O, open, args, returns (
perl-style-subs-io.md).
- Anti-patterns, OO, loops, regex (
perl-style-anti-patterns.md).
- Verify, perlcritic, perltidy, prove on changed files.
Red Flags
- Missing
use strict/use warnings or use v5.36
- Global
-w or $^W
- Tab/mixed indent fighting 4-space perlstyle
- Misaligned closing brace on multi-line BLOCK
- Cuddled
else
- Two-arg or bareword
open
- Unchecked open/close/system return
- Bareword filehandles
foreach (<$fh>) line iteration
`cat $file` slurp
&sub() calls without cause
- Subroutine prototypes
$_[n] argument indexing
- Flattening arrays/hashes into
@_ at call site
- Missing explicit
return on non-trivial subs
- Indirect object notation (
new Class)
$$ref[$i] dereference
- C-style index
for when foreach suffices
- Void
map/grep/backticks
- Overuse of
$_ in long blocks
chop instead of chomp
- Magic numbers
- Lowercase package/module names
- Variable named
file
- snake_case smashed words (
@namesofpresidents)
- Predeclaring all vars at block top
- Non-lexical loop iterator
- Parsing structured data with regex only
- Hairy regex without
/x
- Undocumented exported subs (missing Pod)
- Switch.pm in new code
- String
eval misuse
- Duplicate code / long subs without extraction
Verification
perlcritic --severity 3 (or project .perlcriticrc) on changed paths
perltidy -b -bext='/' or project profile dry-run
prove -l t/ or project test harness
- Head-of-file strict/v5.36 audit
- Capsule checklist on open-or-die and indirect-object grep
References
awesome-guidelines/references/perl-style-learning-note.md
awesome-guidelines/references/perl-style-formatting-layout.md
awesome-guidelines/references/perl-style-strict-scoping.md
awesome-guidelines/references/perl-style-subs-io.md
awesome-guidelines/references/perl-style-anti-patterns.md
1---2name: perl-coding-practices3description: Use when authoring or reviewing Perl, v5.36/strict/warnings, 4-space aligned layout, snake_case and Mixed::Case modules, 3-arg open, explicit subs/I/O, anti-pattern avoidance, and perlcritic/perltidy/prove in CI.4---56# Perl Coding Practices78Application skill for Perl style learning (from the archived `awesome-guidelines` style capsules). When project adopts PBP/perltidy profile, follow that formatter config first.910## Core Principle1112Perl maintainability is **lexical scope + checked I/O**, strict warnings on, 3-arg open, explicit subs, avoid indirect objects and void map/grep.1314## When to Use / NOT1516- Perl scripts, `.pm` modules, CPAN-style distributions, Mojolicious/Dancer apps.17- Setting up perlcritic, perltidy, prove/t harness in CI.1819**NOT when:**2021- Raku (Perl 6), different language foundations.22- Generated `.pm` stubs, validate generators.2324## Workflow25261. **Layout**, indent, braces, alignment (`perl-style-formatting-layout.md`).272. **Scope**, v5.36, my, naming (`perl-style-strict-scoping.md`).283. **Subs/I/O**, open, args, returns (`perl-style-subs-io.md`).294. **Anti-patterns**, OO, loops, regex (`perl-style-anti-patterns.md`).305. **Verify**, perlcritic, perltidy, prove on changed files.3132## Red Flags3334- Missing `use strict`/`use warnings` or `use v5.36`35- Global `-w` or `$^W`36- Tab/mixed indent fighting 4-space perlstyle37- Misaligned closing brace on multi-line BLOCK38- Cuddled `else`39- Two-arg or bareword `open`40- Unchecked open/close/system return41- Bareword filehandles42- `foreach (<$fh>)` line iteration43- `` `cat $file` `` slurp44- `&sub()` calls without cause45- Subroutine prototypes46- `$_[n]` argument indexing47- Flattening arrays/hashes into `@_` at call site48- Missing explicit `return` on non-trivial subs49- Indirect object notation (`new Class`)50- `$$ref[$i]` dereference51- C-style index `for` when foreach suffices52- Void `map`/`grep`/backticks53- Overuse of `$_` in long blocks54- `chop` instead of `chomp`55- Magic numbers56- Lowercase package/module names57- Variable named `file`58- snake_case smashed words (`@namesofpresidents`)59- Predeclaring all vars at block top60- Non-lexical loop iterator61- Parsing structured data with regex only62- Hairy regex without `/x`63- Undocumented exported subs (missing Pod)64- Switch.pm in new code65- String `eval` misuse66- Duplicate code / long subs without extraction6768## Verification6970- `perlcritic --severity 3` (or project `.perlcriticrc`) on changed paths71- `perltidy -b -bext='/'` or project profile dry-run72- `prove -l t/` or project test harness73- Head-of-file strict/v5.36 audit74- Capsule checklist on open-or-die and indirect-object grep757677## References7879- `awesome-guidelines/references/perl-style-learning-note.md`80- `awesome-guidelines/references/perl-style-formatting-layout.md`81- `awesome-guidelines/references/perl-style-strict-scoping.md`82- `awesome-guidelines/references/perl-style-subs-io.md`83- `awesome-guidelines/references/perl-style-anti-patterns.md`