til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

Tidy a file inline

Perltidy is a nifty prettifier or pretty printer as it was called back in the day. I always forget the inline option.

perltidy --nostandard-output --warning-output --backup-and-modify-in-place myperlfile.pl

Do note that the inline modification does not take place if you input are from:

  • standard in
  • going to standard out
  • or the --html flag is provided

From the documentation:

A -b flag will be ignored if input is from standard input or goes to standard output, or if the -html flag is set.

Use the specify the --nostandard-output and work on files.

The short form is:

perltidy -nst -w -b myperlfile.pl

Using a Profile

You can specify your own Perl::Tidy configuration, if you are not using the default configuration

perltidy --nostandard-output --warning-output --backup-and-modify-in-place --pro=t/perltidyrc myperlfile.pl

And the short form:

perltidy -nst -w -b --pro=t/perltidyrc myperlfile.pl

Using perltidy in a pre-commit hook

You can use perltidy in a pre-commit hook.

I recommend the pre-commit framework and the existing hooks.

Please see my TIL: use pre-commit.

Resources and References