ams-perl-pro
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 0
- Forks
- 1
03 SKILL.md 正文
Perl Pro
Overview
Perl's reputation for write-only code is earned by bad Perl — modern, disciplined Perl
(strict, warnings, signatures, CPAN modules, and testing) is a superb text-processing and
glue language. Professional Perl means using the modern toolchain (perl 5.36+, use v5.36 enabling
strict/warnings/signatures), writing readable rather than golfed code, and leaning on CPAN instead
of reinventing.
The through-line: Perl rewards the disciplined — strictures on, warnings heeded, golf left on the course.
When to use
- Writing or reviewing Perl scripts and modules.
- Modernizing legacy Perl (adding strict, tests, structure).
- Text processing, log analysis, and system glue tasks.
- Choosing CPAN modules or structuring distributions.
- Debugging regex, reference, or context issues.
Core concepts
use v5.36;(or strict + warnings + signatures). Modern version bundles enable strict, warnings, and subroutine signatures — the three features that prevent most Perl footguns.use warnings FATAL => 'all'in new code turns warnings into loud failures during development.- Context is the language. Scalar vs list context changes what expressions mean
(
my $n = @arrgives count;my @c = @arrcopies). Masterwantarray, and be deliberate — context bugs are Perl's unique sharp edge. - References for complex data. Arrays of hashes via references (
$orders->[0]{total}); dereference deliberately (@{ $ref },%{ $ref }); autovivification is convenient until it silently creates deep structures from typos — check existence withexistsbefore deep access in critical code. - Regex as a precision tool. Perl regexes are the best in the business — use
/xfor readable multiline patterns with comments, named captures ((?<year>\d{4})), and non-greedy quantifiers deliberately. Compile once (qr//) for repeated use; never build regexes from untrusted input without\Q...\Equoting. - CPAN, not NIH.
cpanmfor installation; prefer well-maintained modules (Mojolicious for web, DBI for databases, Path::Tiny for files, Try::Tiny or builtintryfor exceptions). Check maintenance status — abandoned CPAN modules are a liability. - Testing with Test::More/Test2.
proveruns the suite; test modules, not just scripts;Test::Exception/Test::Warnfor failure modes. Perl's testing culture is one of its best features — use it.
Practical workflow
- Start every file:
use v5.36; use warnings;— non-negotiable. Adduse utf8;anduse open ':std', ':encoding(UTF-8)';for text work. - Structure: scripts for one-offs (
script/), modules inlib/with proper packages (package Orders::Processor;), distributions viaDist::ZillaorMinillafor anything shared. - Write readable Perl. Named variables over
$_in complex code, signatures over@_shifting, early returns, small subs. Golf is for fun, not production. - Handle errors explicitly.
diewith context for programmer errors;Try::Tiny/try-catchor eval-blocks for recoverable failures; check system call returns (open … or die "…: $!"— always include$!). - Test as you go.
t/*.twith Test2; run withprove -l. Mock external systems at the boundary; test the parsing/transform logic heavily — that's where Perl earns its keep. - Mind the encoding. Perl's Unicode handling is powerful but opt-in: decode inputs, encode outputs, and test with non-ASCII data early. Mojibake discovered in production is a rite of passage nobody needs.
Idiomatic snippets:
use v5.36;
# Signatures + named captures + /x readability
sub parse_log_line ($line) {
return unless $line =~ m{
^(?<ts>\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})
\s+ \[(?<level>\w+)\]
\s+ (?<msg>.*)
}x;
return { ts => $+{ts}, level => $+{level}, msg => $+{msg} };
}
# Safe file handling with Path::Tiny
use Path::Tiny;
my $content = path($file)->slurp_utf8;
Common pitfalls
- No strict/warnings. The original sin — typos become new variables, and warnings that would have caught bugs scroll by unheeded.
- Golf in production.
$_,$a, nested map/grep one-liners that take ten minutes to parse. Write for the maintainer, not the leaderboard. - Context bugs. A sub returning a list assigned to scalar (or vice versa) — silent wrong behavior. Be explicit: document return context, or return references.
- Autovivification surprises.
$config->{db}{host}creating intermediate hashes from a typo'd key. Useexists/defined checks orno autovivificationin strict code paths. - Bareword and indirect-object pitfalls.
new ClassvsClass->new— indirect object syntax has parsing gotchas; always use->. - Regex injection. Interpolating user input into regexes without
\Q...\E. And catastrophic backtracking in nested quantifiers — test regexes against adversarial input. - Ignoring CPAN maintenance. Depending on a module untouched since 2009. Check reverse dependencies, recent releases, and open issues before committing.
04 同仓库更多 Skills
web-scrape
Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open/fetch fails on JS-heavy pages, or when you need clean markdown/structured extraction from a site. Requires FIRECRAWL_API_KEY.
design-taste-frontend
tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML/CSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, "AI-made", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code
systematic-debugging
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
requesting-code-review
Use when completing tasks, implementing major features, or before merging to verify work meets requirements
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).