1. Perl
  2. Module
  3. here

perltidy - Format Perl source code

perltidy is a tool for shaping Perl source code. It formats the Perl source code so that it is easy to read.

perltidy source file

Steps to run perltidy on multiple files in a directory

Here are the steps to recursively process all the files in a directory using perltidy . At this point, perltidy itself doesn't seem to implement a way to handle directories recursively.

Make a backup first

Make a backup of your directory first. This is to return even if you make a mistake. Back up each directory in a different location.

Find the desired file

First, find the desired file using the find2perl command. I think files ending in .pm and files ending in .pl will be formatted. The target directory name is dir.

find2perl perl_lib/-name "* .p [ml]" | perl

If the target file is correct, proceed to the next step.

Run perltidy

Now let's run perltidy on the output file.

find2perl perl_lib/-name "* .p [ml]" | perl | perl -ne "system('perltidy', $_)"

You now have a file with the extension .tdy . This is the formatted source file. Let's check if the output is correct.

Overwrite the original file with a file with a .tdy extension

Overwrites the original file with a file with a .tdy extension. That's it.

find2perl perl_lib/-name "* .p [ml]" | perl | perl -MFile::Copy -ne "chomp $_; move ($_.'. Tdy', $_)"

I want perltidy to have the ability to easily format multiple files in a directory.

(Reference) File::Copy

Related Informatrion