5 minimums for any perl script?

Damian Conway damian at conway.org
Sun Jan 29 23:11:17 GMT 2012

> So if Perl Best Practices is too much, and you could only have 5 rules
> for any perl script, what would they be?

Can I have six, please Sir???

These are in decreasing order of "bang for your buck"
[and with PBP references, in case PBP *isn't* too much]...

1. Commenting: Code in commented paragraphs.
   [Ch2: "Chunking"]

2. Layout: Agree upon a single coherent layout style and automate it
with 'perltidy'.
   [Ch2: "Automated Layout"]

3. Strictures: Always 'use strict' (and 'use warnings' during development) and
   explicitly state your minimum Perl version requirement. (e.g. 'use v5.10')
   [Ch18: "Strictures", "Warnings"]

4. Naming: Use grammatical templates of at least two words when forming
   identifiers (or at least those whose scope extends beyond a single block).
   (e.g. '<adj>_<noun>' for vars, '<verb>_<noun>' for subs)
   [Ch3: "Identifiers"]

5. Subroutine APIs: In a subroutine, always unpack @_ first (using named args
    if there are more than three parameters), and always return via an
explicit 'return'.
   [Ch9: "Argument Lists", "Named Arguments", "Implicit Returns"]

6. Regexes: Always use the '/x' flag and named captures, and if the regex
   is complex, factor components out into independent named subpatterns.
   [Ch12: "Extended Formatting", no refs for the named stuff (which
post-dates PBP)]


More information about the london.pm mailing list