Code Style and Linting

If you are looking for good general advices regarding Perl coding, Damian Conway's Perl Best Practices is a good reference.

To prettify your code, you can use the module Perl-Tidy.

To install with cpanminus:

1
cpanm Perl-Tidy

or via the regular cpan install utility:

1
cpan Perl-Tidy

And then, you can use the provided perltidy utility program to reformat your code.

1
2
# modify file in-place and save old version as some_script.pl.bak
$ perltidy -b some_script.pl

perltidy has a lot of configuration options to cater to every taste. They are documented here.

There is also tidyview, a visual interface that allows you to tweak the different options and immediately see the result.

If you want to enforce coding practices, there is also Perl::Critic. It comes with the rules described in the book Perl Best Practices mentioned previously, but plenty of plugins exist, and it can be customized to fit any in-house coding rules.

To install:

1
2
3
4
5
# via cpanminus
cpanm Perl-Critic

# via the classic 'cpan' installation tool
cpan Perl-Critic

To use:

1
$ perlcritic some_script.pl

The tool has many, many configuration tweaks, see its documentation for the full scoop on them.


Help us explain this better! File a GitHub issue at https://github.com/exercism/perl5/issues if you have suggestions, or submit a patch with improvements to the https://github.com/exercism/perl5/blob/master/docs/RESOURCES.md file.