Perl Development Skill
Assist with all aspects of Perl development including creating files, writing code, running scripts, debugging, and testing.
Creating New Files
When creating a new Perl script (.pl) or module (.pm), always include the file header from CLAUDE.md using the Perl template. Every script must begin with:
#!/usr/bin/env perl
use strict;
use warnings;
use v5.36;
For modules, use the standard package structure:
package MyModule;
use strict;
use warnings;
use v5.36;
# module code here
1;
Running and Testing
- Run scripts with:
perl -w <script.pl>
- Check syntax without executing:
perl -c <script.pl>
- Run tests with:
prove -v or perl -Ilib t/*.t
- Use
perl -d <script.pl> information to help debug issues when the user asks
Code Quality
- Always
use strict and use warnings
- Prefer modern Perl idioms (v5.36+ features like
use v5.36 which enables strict, signatures, etc.)
- Use descriptive variable names following snake_case convention
- Use Perl's built-in documentation: check
perldoc for module usage
- Prefer core modules over external dependencies when practical
- Use three-argument
open with lexical filehandles
- Handle errors explicitly (
open my $fh, '<', $file or die "Cannot open $file: $!")
Debugging
Built-in Perl debugging
- Add
use Data::Dumper for inspecting complex data structures
- Use
warn for debug output to STDERR
- Check for common issues: missing semicolons, incorrect sigils, scope problems
- Run
perl -MO=Deparse <script.pl> to see how Perl interprets the code
Perl debugger (perl -d)
- Launch with:
perl -d <script.pl>
- Key commands:
n (next line), s (step into), c (continue)
b <line> (set breakpoint), B <line> (delete breakpoint)
p <expr> (print expression), x <expr> (dump structure)
l (list source), T (stack backtrace)
w <expr> (watch expression), R (restart)
q (quit)
- Use
perl -d -e 0 for an interactive Perl shell
Perl::Critic (static analysis)
- Enforces coding standards based on Perl Best Practices
- Run with:
perlcritic <script.pl>
- Severity levels 1 (most strict) to 5 (least strict):
perlcritic --severity 3 <script.pl>
- Use a
.perlcriticrc file for project-specific policies
- Disable specific policies inline:
## no critic (PolicyName)
- Install with:
cpanm Perl::Critic
Perl::Tidy (code formatter)
- Reformats Perl code to a consistent style
- Run with:
perltidy <script.pl> (creates <script.pl>.tdy)
- In-place formatting:
perltidy -b <script.pl>
- Use a
.perltidyrc file for project-specific settings
- Install with:
cpanm Perl::Tidy
Test::More and prove (testing framework)
- Perl's standard testing framework
- Run tests with:
prove -v or prove -v -r t/
- Run a single test:
prove -v t/specific_test.t
- Test file structure:
use Test::More;
is(my_function(1, 2), 3, 'addition works');
ok(defined $result, 'result is defined');
like($string, qr/pattern/, 'string matches pattern');
is_deeply(\@got, \@expected, 'arrays match');
done_testing();
- Additional test modules:
Test::Exception -- test that code dies/lives as expected
Test::Warn -- test warning output
Test::Deep -- flexible deep structure comparison
Test::MockObject -- mock objects for unit testing
CPAN Modules
- Install modules with:
cpanm <Module::Name>
- Check if a module is installed:
perl -M<Module::Name> -e1
- Prefer well-maintained, widely-used modules
Argument Handling
- If
$ARGUMENTS is a filename ending in .pl or .pm, work with that file
- If
$ARGUMENTS is "new ", scaffold a new file with proper headers
- If
$ARGUMENTS is "run ", execute the script and report output
- If
$ARGUMENTS is "test", run the project's test suite
- Otherwise, treat
$ARGUMENTS as a general Perl development request
1---2name: perl3description: Full Perl development aid. Use when the user wants to create, edit, run, debug, or test Perl scripts and modules. Scaffolds files with proper headers, follows Perl best practices, executes scripts, and assists with debugging.4---56# Perl Development Skill78Assist with all aspects of Perl development including creating files, writing code, running scripts, debugging, and testing.910## Creating New Files1112When creating a new Perl script (.pl) or module (.pm), always include the file header from CLAUDE.md using the Perl template. Every script must begin with:1314```perl15#!/usr/bin/env perl16use strict;17use warnings;18use v5.36;19```2021For modules, use the standard package structure:2223```perl24package MyModule;25use strict;26use warnings;27use v5.36;2829# module code here30311;32```3334## Running and Testing3536- Run scripts with: `perl -w <script.pl>`37- Check syntax without executing: `perl -c <script.pl>`38- Run tests with: `prove -v` or `perl -Ilib t/*.t`39- Use `perl -d <script.pl>` information to help debug issues when the user asks4041## Code Quality4243- Always `use strict` and `use warnings`44- Prefer modern Perl idioms (v5.36+ features like `use v5.36` which enables strict, signatures, etc.)45- Use descriptive variable names following snake_case convention46- Use Perl's built-in documentation: check `perldoc` for module usage47- Prefer core modules over external dependencies when practical48- Use three-argument `open` with lexical filehandles49- Handle errors explicitly (`open my $fh, '<', $file or die "Cannot open $file: $!"`)5051## Debugging5253### Built-in Perl debugging54- Add `use Data::Dumper` for inspecting complex data structures55- Use `warn` for debug output to STDERR56- Check for common issues: missing semicolons, incorrect sigils, scope problems57- Run `perl -MO=Deparse <script.pl>` to see how Perl interprets the code5859### Perl debugger (perl -d)60- Launch with: `perl -d <script.pl>`61- Key commands:62 - `n` (next line), `s` (step into), `c` (continue)63 - `b <line>` (set breakpoint), `B <line>` (delete breakpoint)64 - `p <expr>` (print expression), `x <expr>` (dump structure)65 - `l` (list source), `T` (stack backtrace)66 - `w <expr>` (watch expression), `R` (restart)67 - `q` (quit)68- Use `perl -d -e 0` for an interactive Perl shell6970### Perl::Critic (static analysis)71- Enforces coding standards based on Perl Best Practices72- Run with: `perlcritic <script.pl>`73- Severity levels 1 (most strict) to 5 (least strict): `perlcritic --severity 3 <script.pl>`74- Use a `.perlcriticrc` file for project-specific policies75- Disable specific policies inline: `## no critic (PolicyName)`76- Install with: `cpanm Perl::Critic`7778### Perl::Tidy (code formatter)79- Reformats Perl code to a consistent style80- Run with: `perltidy <script.pl>` (creates `<script.pl>.tdy`)81- In-place formatting: `perltidy -b <script.pl>`82- Use a `.perltidyrc` file for project-specific settings83- Install with: `cpanm Perl::Tidy`8485### Test::More and prove (testing framework)86- Perl's standard testing framework87- Run tests with: `prove -v` or `prove -v -r t/`88- Run a single test: `prove -v t/specific_test.t`89- Test file structure:90 ```perl91 use Test::More;9293 is(my_function(1, 2), 3, 'addition works');94 ok(defined $result, 'result is defined');95 like($string, qr/pattern/, 'string matches pattern');96 is_deeply(\@got, \@expected, 'arrays match');9798 done_testing();99 ```100- Additional test modules:101 - `Test::Exception` -- test that code dies/lives as expected102 - `Test::Warn` -- test warning output103 - `Test::Deep` -- flexible deep structure comparison104 - `Test::MockObject` -- mock objects for unit testing105106## CPAN Modules107108- Install modules with: `cpanm <Module::Name>`109- Check if a module is installed: `perl -M<Module::Name> -e1`110- Prefer well-maintained, widely-used modules111112## Argument Handling113114- If `$ARGUMENTS` is a filename ending in `.pl` or `.pm`, work with that file115- If `$ARGUMENTS` is "new <filename>", scaffold a new file with proper headers116- If `$ARGUMENTS` is "run <filename>", execute the script and report output117- If `$ARGUMENTS` is "test", run the project's test suite118- Otherwise, treat `$ARGUMENTS` as a general Perl development request