Source:
Http://www.cnblogs.com/itech/archive/2013/02/18/2915279.html
The beautifully formatted Perl code is not only pleasing to the eye, but also easy to read.
Perltidy is a small project of SourceForge, after we have written a messy code, he can be like magic to tidy up the code, come and experience it!!!
Perltidy Home: http://perltidy.sourceforge.net/perltidy.html
Installation method:
Go to the extracted directory and execute the command
Perl makefile.pl
Make
Make Test
Make install
How to use:
Configure VIM so that we can beautify our code when we write the code without leaving vim.
In the last line of/ETC/VIMRC: (meaning shortcut key pt to call Perltidy)
Map, PT:%! Perltidy
After writing the Perl code, in the VIM command mode, enter the command ", PT" to directly organize the code format.
Attention:
1) If you need to install into your own home directory, as follows:
Perl makefile.pl Prefix=~/perl
Setenv Perl5lib ~/perl/lib/site_perl/5.8.3
2) Called with Config, which defaults to. PERLTIDYRC:
In the home directory by default, Perltidy Yourscript will generate YOURSCRIPT.TDY files and need to manually overwrite the original files with TDY files.
If you only use the specified profile Perltidy-pro=tidyconfigfile yourscript > Yourscript.tdy, then overwrite the original file with the Tdy file.
The default profile instance. perltidyrc File:
# A simple of a. PERLTIDYRC configuration file
# This implements a highly spaced style
-BL # braces on new lines
-pt=0 # parens not tight @ all
-bt=0 # braces not tight
-sbt=0 # square brackets not tight
My configuration file:
-GNU # GNU Coding standards
-PBP #--perl-best-practices
-i=2 # use 2 columns per indentation level
-ci=2 # Continuation indentation is extra indentation spaces applied when a long line is broken.
-ce # Else and elsif is follow immediately after the curly brace closing the previous block
-NBL # places an opening brace on the same line as the keyword introducing it.
-bt=2 # braces not tight
-sbt=2 # square brackets not tight
-pt=2 # Tightness of curly braces, parentheses, and square brackets.
-NSFS #--space-for-semicolon
-nsak=s #--nospace-after-keyword=s removes keywords.
-DWS #--delete-old-whitespace
Use Perltidy to beautify Perl code in vim