]> git.donarmstrong.com Git - perltidy.git/blob - docs/perltidy.html
New upstream version 20220217
[perltidy.git] / docs / perltidy.html
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title></title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:root@localhost" />
8 </head>
9
10 <body>
11
12
13
14 <ul id="index">
15   <li><a href="#NAME">NAME</a></li>
16   <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
17   <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
18   <li><a href="#EXAMPLES">EXAMPLES</a></li>
19   <li><a href="#OPTIONS---OVERVIEW">OPTIONS - OVERVIEW</a>
20     <ul>
21       <li><a href="#I-O-control">I/O control</a></li>
22     </ul>
23   </li>
24   <li><a href="#FORMATTING-OPTIONS">FORMATTING OPTIONS</a>
25     <ul>
26       <li><a href="#Basic-Options">Basic Options</a></li>
27       <li><a href="#Code-Indentation-Control">Code Indentation Control</a></li>
28       <li><a href="#Whitespace-Control">Whitespace Control</a></li>
29       <li><a href="#Comment-Controls">Comment Controls</a></li>
30       <li><a href="#Skipping-Selected-Sections-of-Code">Skipping Selected Sections of Code</a></li>
31       <li><a href="#Line-Break-Control">Line Break Control</a></li>
32       <li><a href="#Controlling-List-Formatting">Controlling List Formatting</a></li>
33       <li><a href="#Retaining-or-Ignoring-Existing-Line-Breaks">Retaining or Ignoring Existing Line Breaks</a></li>
34       <li><a href="#Blank-Line-Control">Blank Line Control</a></li>
35       <li><a href="#Styles">Styles</a></li>
36       <li><a href="#Controlling-Vertical-Alignment">Controlling Vertical Alignment</a></li>
37       <li><a href="#Other-Controls">Other Controls</a></li>
38     </ul>
39   </li>
40   <li><a href="#HTML-OPTIONS">HTML OPTIONS</a></li>
41   <li><a href="#SOME-COMMON-INPUT-CONVENTIONS">SOME COMMON INPUT CONVENTIONS</a>
42     <ul>
43       <li><a href="#Specifying-Block-Types">Specifying Block Types</a></li>
44       <li><a href="#Specifying-File-Extensions">Specifying File Extensions</a></li>
45     </ul>
46   </li>
47   <li><a href="#SWITCHES-WHICH-MAY-BE-NEGATED">SWITCHES WHICH MAY BE NEGATED</a></li>
48   <li><a href="#LIMITATIONS">LIMITATIONS</a></li>
49   <li><a href="#FILES">FILES</a></li>
50   <li><a href="#ERROR-HANDLING">ERROR HANDLING</a></li>
51   <li><a href="#SEE-ALSO">SEE ALSO</a></li>
52   <li><a href="#INSTALLATION">INSTALLATION</a></li>
53   <li><a href="#VERSION">VERSION</a></li>
54   <li><a href="#BUG-REPORTS">BUG REPORTS</a></li>
55   <li><a href="#COPYRIGHT">COPYRIGHT</a></li>
56   <li><a href="#LICENSE">LICENSE</a></li>
57   <li><a href="#DISCLAIMER">DISCLAIMER</a></li>
58 </ul>
59
60 <h1 id="NAME">NAME</h1>
61
62 <p>perltidy - a perl script indenter and reformatter</p>
63
64 <h1 id="SYNOPSIS">SYNOPSIS</h1>
65
66 <pre><code>    perltidy [ options ] file1 file2 file3 ...
67             (output goes to file1.tdy, file2.tdy, file3.tdy, ...)
68     perltidy [ options ] file1 -o outfile
69     perltidy [ options ] file1 -st &gt;outfile
70     perltidy [ options ] &lt;infile &gt;outfile</code></pre>
71
72 <h1 id="DESCRIPTION">DESCRIPTION</h1>
73
74 <p>Perltidy reads a perl script and writes an indented, reformatted script.</p>
75
76 <p>Many users will find enough information in <a href="#EXAMPLES">&quot;EXAMPLES&quot;</a> to get started. New users may benefit from the short tutorial which can be found at http://perltidy.sourceforge.net/tutorial.html</p>
77
78 <p>A convenient aid to systematically defining a set of style parameters can be found at http://perltidy.sourceforge.net/stylekey.html</p>
79
80 <p>Perltidy can produce output on either of two modes, depending on the existence of an <b>-html</b> flag. Without this flag, the output is passed through a formatter. The default formatting tries to follow the recommendations in perlstyle(1), but it can be controlled in detail with numerous input parameters, which are described in <a href="#FORMATTING-OPTIONS">&quot;FORMATTING OPTIONS&quot;</a>.</p>
81
82 <p>When the <b>-html</b> flag is given, the output is passed through an HTML formatter which is described in <a href="#HTML-OPTIONS">&quot;HTML OPTIONS&quot;</a>.</p>
83
84 <h1 id="EXAMPLES">EXAMPLES</h1>
85
86 <pre><code>  perltidy somefile.pl</code></pre>
87
88 <p>This will produce a file <i>somefile.pl.tdy</i> containing the script reformatted using the default options, which approximate the style suggested in perlstyle(1). The source file <i>somefile.pl</i> is unchanged.</p>
89
90 <pre><code>  perltidy *.pl</code></pre>
91
92 <p>Execute perltidy on all <i>.pl</i> files in the current directory with the default options. The output will be in files with an appended <i>.tdy</i> extension. For any file with an error, there will be a file with extension <i>.ERR</i>.</p>
93
94 <pre><code>  perltidy -b file1.pl file2.pl</code></pre>
95
96 <p>Modify <i>file1.pl</i> and <i>file2.pl</i> in place, and backup the originals to <i>file1.pl.bak</i> and <i>file2.pl.bak</i>. If <i>file1.pl.bak</i> and/or <i>file2.pl.bak</i> already exist, they will be overwritten.</p>
97
98 <pre><code>  perltidy -b -bext=&#39;/&#39; file1.pl file2.pl</code></pre>
99
100 <p>Same as the previous example except that the backup files <i>file1.pl.bak</i> and <i>file2.pl.bak</i> will be deleted if there are no errors.</p>
101
102 <pre><code>  perltidy -gnu somefile.pl</code></pre>
103
104 <p>Execute perltidy on file <i>somefile.pl</i> with a style which approximates the GNU Coding Standards for C programs. The output will be <i>somefile.pl.tdy</i>.</p>
105
106 <pre><code>  perltidy -i=3 somefile.pl</code></pre>
107
108 <p>Execute perltidy on file <i>somefile.pl</i>, with 3 columns for each level of indentation (<b>-i=3</b>) instead of the default 4 columns. There will not be any tabs in the reformatted script, except for any which already exist in comments, pod documents, quotes, and here documents. Output will be <i>somefile.pl.tdy</i>.</p>
109
110 <pre><code>  perltidy -i=3 -et=8 somefile.pl</code></pre>
111
112 <p>Same as the previous example, except that leading whitespace will be entabbed with one tab character per 8 spaces.</p>
113
114 <pre><code>  perltidy -ce -l=72 somefile.pl</code></pre>
115
116 <p>Execute perltidy on file <i>somefile.pl</i> with all defaults except use &quot;cuddled elses&quot; (<b>-ce</b>) and a maximum line length of 72 columns (<b>-l=72</b>) instead of the default 80 columns.</p>
117
118 <pre><code>  perltidy -g somefile.pl</code></pre>
119
120 <p>Execute perltidy on file <i>somefile.pl</i> and save a log file <i>somefile.pl.LOG</i> which shows the nesting of braces, parentheses, and square brackets at the start of every line.</p>
121
122 <pre><code>  perltidy -html somefile.pl</code></pre>
123
124 <p>This will produce a file <i>somefile.pl.html</i> containing the script with html markup. The output file will contain an embedded style sheet in the &lt;HEAD&gt; section which may be edited to change the appearance.</p>
125
126 <pre><code>  perltidy -html -css=mystyle.css somefile.pl</code></pre>
127
128 <p>This will produce a file <i>somefile.pl.html</i> containing the script with html markup. This output file will contain a link to a separate style sheet file <i>mystyle.css</i>. If the file <i>mystyle.css</i> does not exist, it will be created. If it exists, it will not be overwritten.</p>
129
130 <pre><code>  perltidy -html -pre somefile.pl</code></pre>
131
132 <p>Write an html snippet with only the PRE section to <i>somefile.pl.html</i>. This is useful when code snippets are being formatted for inclusion in a larger web page. No style sheet will be written in this case.</p>
133
134 <pre><code>  perltidy -html -ss &gt;mystyle.css</code></pre>
135
136 <p>Write a style sheet to <i>mystyle.css</i> and exit.</p>
137
138 <pre><code>  perltidy -html -frm mymodule.pm</code></pre>
139
140 <p>Write html with a frame holding a table of contents and the source code. The output files will be <i>mymodule.pm.html</i> (the frame), <i>mymodule.pm.toc.html</i> (the table of contents), and <i>mymodule.pm.src.html</i> (the source code).</p>
141
142 <h1 id="OPTIONS---OVERVIEW">OPTIONS - OVERVIEW</h1>
143
144 <p>The entire command line is scanned for options, and they are processed before any files are processed. As a result, it does not matter whether flags are before or after any filenames. However, the relative order of parameters is important, with later parameters overriding the values of earlier parameters.</p>
145
146 <p>For each parameter, there is a long name and a short name. The short names are convenient for keyboard input, while the long names are self-documenting and therefore useful in scripts. It is customary to use two leading dashes for long names, but one may be used.</p>
147
148 <p>Most parameters which serve as on/off flags can be negated with a leading &quot;n&quot; (for the short name) or a leading &quot;no&quot; or &quot;no-&quot; (for the long name). For example, the flag to outdent long quotes is <b>-olq</b> or <b>--outdent-long-quotes</b>. The flag to skip this is <b>-nolq</b> or <b>--nooutdent-long-quotes</b> or <b>--no-outdent-long-quotes</b>.</p>
149
150 <p>Options may not be bundled together. In other words, options <b>-q</b> and <b>-g</b> may NOT be entered as <b>-qg</b>.</p>
151
152 <p>Option names may be terminated early as long as they are uniquely identified. For example, instead of <b>--dump-token-types</b>, it would be sufficient to enter <b>--dump-tok</b>, or even <b>--dump-t</b>, to uniquely identify this command.</p>
153
154 <h2 id="I-O-control">I/O control</h2>
155
156 <p>The following parameters concern the files which are read and written.</p>
157
158 <dl>
159
160 <dt id="h---help"><b>-h</b>, <b>--help</b></dt>
161 <dd>
162
163 <p>Show summary of usage and exit.</p>
164
165 </dd>
166 <dt id="o-filename---outfile-filename"><b>-o</b>=filename, <b>--outfile</b>=filename</dt>
167 <dd>
168
169 <p>Name of the output file (only if a single input file is being processed). If no output file is specified, and output is not redirected to the standard output (see <b>-st</b>), the output will go to <i>filename.tdy</i>. [Note: - does not redirect to standard output. Use <b>-st</b> instead.]</p>
170
171 </dd>
172 <dt id="st---standard-output"><b>-st</b>, <b>--standard-output</b></dt>
173 <dd>
174
175 <p>Perltidy must be able to operate on an arbitrarily large number of files in a single run, with each output being directed to a different output file. Obviously this would conflict with outputting to the single standard output device, so a special flag, <b>-st</b>, is required to request outputting to the standard output. For example,</p>
176
177 <pre><code>  perltidy somefile.pl -st &gt;somefile.new.pl</code></pre>
178
179 <p>This option may only be used if there is just a single input file. The default is <b>-nst</b> or <b>--nostandard-output</b>.</p>
180
181 </dd>
182 <dt id="se---standard-error-output"><b>-se</b>, <b>--standard-error-output</b></dt>
183 <dd>
184
185 <p>If perltidy detects an error when processing file <i>somefile.pl</i>, its default behavior is to write error messages to file <i>somefile.pl.ERR</i>. Use <b>-se</b> to cause all error messages to be sent to the standard error output stream instead. This directive may be negated with <b>-nse</b>. Thus, you may place <b>-se</b> in a <i>.perltidyrc</i> and override it when desired with <b>-nse</b> on the command line.</p>
186
187 </dd>
188 <dt id="oext-ext---output-file-extension-ext"><b>-oext</b>=ext, <b>--output-file-extension</b>=ext</dt>
189 <dd>
190
191 <p>Change the extension of the output file to be <i>ext</i> instead of the default <i>tdy</i> (or <i>html</i> in case the -<b>-html</b> option is used). See <a href="#Specifying-File-Extensions">&quot;Specifying File Extensions&quot;</a>.</p>
192
193 </dd>
194 <dt id="opath-path---output-path-path"><b>-opath</b>=path, <b>--output-path</b>=path</dt>
195 <dd>
196
197 <p>When perltidy creates a filename for an output file, by default it merely appends an extension to the path and basename of the input file. This parameter causes the path to be changed to <i>path</i> instead.</p>
198
199 <p>The path should end in a valid path separator character, but perltidy will try to add one if it is missing.</p>
200
201 <p>For example</p>
202
203 <pre><code> perltidy somefile.pl -opath=/tmp/</code></pre>
204
205 <p>will produce <i>/tmp/somefile.pl.tdy</i>. Otherwise, <i>somefile.pl.tdy</i> will appear in whatever directory contains <i>somefile.pl</i>.</p>
206
207 <p>If the path contains spaces, it should be placed in quotes.</p>
208
209 <p>This parameter will be ignored if output is being directed to standard output, or if it is being specified explicitly with the <b>-o=s</b> parameter.</p>
210
211 </dd>
212 <dt id="b---backup-and-modify-in-place"><b>-b</b>, <b>--backup-and-modify-in-place</b></dt>
213 <dd>
214
215 <p>Modify the input file or files in-place and save the original with the extension <i>.bak</i>. Any existing <i>.bak</i> file will be deleted. See next item for changing the default backup extension, and for eliminating the backup file altogether.</p>
216
217 <p>A <b>-b</b> flag will be ignored if input is from standard input or goes to standard output, or if the <b>-html</b> flag is set.</p>
218
219 <p>In particular, if you want to use both the <b>-b</b> flag and the <b>-pbp</b> (--perl-best-practices) flag, then you must put a <b>-nst</b> flag after the <b>-pbp</b> flag because it contains a <b>-st</b> flag as one of its components, which means that output will go to the standard output stream.</p>
220
221 </dd>
222 <dt id="bext-ext---backup-file-extension-ext"><b>-bext</b>=ext, <b>--backup-file-extension</b>=ext</dt>
223 <dd>
224
225 <p>This parameter serves two purposes: (1) to change the extension of the backup file to be something other than the default <i>.bak</i>, and (2) to indicate that no backup file should be saved.</p>
226
227 <p>To change the default extension to something other than <i>.bak</i> see <a href="#Specifying-File-Extensions">&quot;Specifying File Extensions&quot;</a>.</p>
228
229 <p>A backup file of the source is always written, but you can request that it be deleted at the end of processing if there were no errors. This is risky unless the source code is being maintained with a source code control system.</p>
230
231 <p>To indicate that the backup should be deleted include one forward slash, <b>/</b>, in the extension. If any text remains after the slash is removed it will be used to define the backup file extension (which is always created and only deleted if there were no errors).</p>
232
233 <p>Here are some examples:</p>
234
235 <pre><code>  Parameter           Extension          Backup File Treatment
236   &lt;-bext=bak&gt;         F&lt;.bak&gt;            Keep (same as the default behavior)
237   &lt;-bext=&#39;/&#39;&gt;         F&lt;.bak&gt;            Delete if no errors
238   &lt;-bext=&#39;/backup&#39;&gt;   F&lt;.backup&gt;         Delete if no errors
239   &lt;-bext=&#39;original/&#39;&gt; F&lt;.original&gt;       Delete if no errors</code></pre>
240
241 </dd>
242 <dt id="w---warning-output"><b>-w</b>, <b>--warning-output</b></dt>
243 <dd>
244
245 <p>Setting <b>-w</b> causes any non-critical warning messages to be reported as errors. These include messages about possible pod problems, possibly bad starting indentation level, and cautions about indirect object usage. The default, <b>-nw</b> or <b>--nowarning-output</b>, is not to include these warnings.</p>
246
247 </dd>
248 <dt id="q---quiet"><b>-q</b>, <b>--quiet</b></dt>
249 <dd>
250
251 <p>Deactivate error messages (for running under an editor).</p>
252
253 <p>For example, if you use a vi-style editor, such as vim, you may execute perltidy as a filter from within the editor using something like</p>
254
255 <pre><code> :n1,n2!perltidy -q</code></pre>
256
257 <p>where <code>n1,n2</code> represents the selected text. Without the <b>-q</b> flag, any error message may mess up your screen, so be prepared to use your &quot;undo&quot; key.</p>
258
259 </dd>
260 <dt id="log---logfile"><b>-log</b>, <b>--logfile</b></dt>
261 <dd>
262
263 <p>Save the <i>.LOG</i> file, which has many useful diagnostics. Perltidy always creates a <i>.LOG</i> file, but by default it is deleted unless a program bug is suspected. Setting the <b>-log</b> flag forces the log file to be saved.</p>
264
265 </dd>
266 <dt id="g-n---logfile-gap-n"><b>-g=n</b>, <b>--logfile-gap=n</b></dt>
267 <dd>
268
269 <p>Set maximum interval between input code lines in the logfile. This purpose of this flag is to assist in debugging nesting errors. The value of <code>n</code> is optional. If you set the flag <b>-g</b> without the value of <code>n</code>, it will be taken to be 1, meaning that every line will be written to the log file. This can be helpful if you are looking for a brace, paren, or bracket nesting error.</p>
270
271 <p>Setting <b>-g</b> also causes the logfile to be saved, so it is not necessary to also include <b>-log</b>.</p>
272
273 <p>If no <b>-g</b> flag is given, a value of 50 will be used, meaning that at least every 50th line will be recorded in the logfile. This helps prevent excessively long log files.</p>
274
275 <p>Setting a negative value of <code>n</code> is the same as not setting <b>-g</b> at all.</p>
276
277 </dd>
278 <dt id="npro---noprofile"><b>-npro</b> <b>--noprofile</b></dt>
279 <dd>
280
281 <p>Ignore any <i>.perltidyrc</i> command file. Normally, perltidy looks first in your current directory for a <i>.perltidyrc</i> file of parameters. (The format is described below). If it finds one, it applies those options to the initial default values, and then it applies any that have been defined on the command line. If no <i>.perltidyrc</i> file is found, it looks for one in your home directory.</p>
282
283 <p>If you set the <b>-npro</b> flag, perltidy will not look for this file.</p>
284
285 </dd>
286 <dt id="pro-filename-or---profile-filename"><b>-pro=filename</b> or <b>--profile=filename</b></dt>
287 <dd>
288
289 <p>To simplify testing and switching .perltidyrc files, this command may be used to specify a configuration file which will override the default name of .perltidyrc. There must not be a space on either side of the &#39;=&#39; sign. For example, the line</p>
290
291 <pre><code>   perltidy -pro=testcfg</code></pre>
292
293 <p>would cause file <i>testcfg</i> to be used instead of the default <i>.perltidyrc</i>.</p>
294
295 <p>A pathname begins with three dots, e.g. &quot;.../.perltidyrc&quot;, indicates that the file should be searched for starting in the current directory and working upwards. This makes it easier to have multiple projects each with their own .perltidyrc in their root directories.</p>
296
297 </dd>
298 <dt id="opt---show-options"><b>-opt</b>, <b>--show-options</b></dt>
299 <dd>
300
301 <p>Write a list of all options used to the <i>.LOG</i> file. Please see <b>--dump-options</b> for a simpler way to do this.</p>
302
303 </dd>
304 <dt id="f---force-read-binary"><b>-f</b>, <b>--force-read-binary</b></dt>
305 <dd>
306
307 <p>Force perltidy to process binary files. To avoid producing excessive error messages, perltidy skips files identified by the system as non-text. However, valid perl scripts containing binary data may sometimes be identified as non-text, and this flag forces perltidy to process them.</p>
308
309 </dd>
310 <dt id="ast---assert-tidy"><b>-ast</b>, <b>--assert-tidy</b></dt>
311 <dd>
312
313 <p>This flag asserts that the input and output code streams are identical, or in other words that the input code is already &#39;tidy&#39; according to the formatting parameters. If this is not the case, an error message noting this is produced. This error message will cause the process to return a non-zero exit code. The test for this is made by comparing an MD5 hash value for the input and output code streams. This flag has no other effect on the functioning of perltidy. This might be useful for certain code maintenance operations. Note: you will not see this message if you have error messages turned off with the -quiet flag.</p>
314
315 </dd>
316 <dt id="asu---assert-untidy"><b>-asu</b>, <b>--assert-untidy</b></dt>
317 <dd>
318
319 <p>This flag asserts that the input and output code streams are different, or in other words that the input code is &#39;untidy&#39; according to the formatting parameters. If this is not the case, an error message noting this is produced. This flag has no other effect on the functioning of perltidy.</p>
320
321 </dd>
322 <dt id="sal-s---sub-alias-list-s"><b>-sal=s</b>, <b>--sub-alias-list=s</b></dt>
323 <dd>
324
325 <p>This flag causes one or more words to be treated the same as if they were the keyword &#39;sub&#39;. The string <b>s</b> contains one or more alias words, separated by spaces or commas.</p>
326
327 <p>For example,</p>
328
329 <pre><code>        perltidy -sal=&#39;method fun _sub M4&#39;</code></pre>
330
331 <p>will cause the perltidy to treate the words &#39;method&#39;, &#39;fun&#39;, &#39;_sub&#39; and &#39;M4&#39; to be treated the same as if they were &#39;sub&#39;. Note that if the alias words are separated by spaces then the string of words should be placed in quotes.</p>
332
333 <p>Note that several other parameters accept a list of keywords, including &#39;sub&#39; (see <a href="#Specifying-Block-Types">&quot;Specifying Block Types&quot;</a>). You do not need to include any sub aliases in these lists. Just include keyword &#39;sub&#39; if you wish, and all aliases are automatically included.</p>
334
335 </dd>
336 <dt id="gal-s---grep-alias-list-s"><b>-gal=s</b>, <b>--grep-alias-list=s</b></dt>
337 <dd>
338
339 <p>This flag allows a code block following an external &#39;list operator&#39; function to be formatted as if it followed one of the builtin keywords <b>grep</b>, <b>map</b> or <b>sort</b>. The string <b>s</b> contains the names of one or more such list operators, separated by spaces or commas.</p>
340
341 <p>By &#39;list operator&#39; is meant a function which is invoked in the form</p>
342
343 <pre><code>      word {BLOCK} @list</code></pre>
344
345 <p>Perltidy tries to keep code blocks for these functions intact, since they are usually short, and does not automatically break after the closing brace since a list may follow. It also does some special handling of continuation indentation.</p>
346
347 <p>For example, the code block arguments to functions &#39;My_grep&#39; and &#39;My_map&#39; can be given formatting like &#39;grep&#39; with</p>
348
349 <pre><code>        perltidy -gal=&#39;My_grep My_map&#39;</code></pre>
350
351 <p>By default, the following list operators in List::Util are automatically included:</p>
352
353 <pre><code>      all any first none notall reduce reductions</code></pre>
354
355 <p>Any operators specified with <b>--grep-alias-list</b> are added to this list. The next parameter can be used to remove words from this default list.</p>
356
357 </dd>
358 <dt id="gaxl-s---grep-alias-exclusion-list-s"><b>-gaxl=s</b>, <b>--grep-alias-exclusion-list=s</b></dt>
359 <dd>
360
361 <p>The <b>-gaxl=s</b> flag provides a method for removing any of the default list operators given above by listing them in the string <b>s</b>. To remove all of the default operators use <b>-gaxl=&#39;*&#39;</b>.</p>
362
363 </dd>
364 </dl>
365
366 <h1 id="FORMATTING-OPTIONS">FORMATTING OPTIONS</h1>
367
368 <h2 id="Basic-Options">Basic Options</h2>
369
370 <dl>
371
372 <dt id="notidy"><b>--notidy</b></dt>
373 <dd>
374
375 <p>This flag disables all formatting and causes the input to be copied unchanged to the output except for possible changes in line ending characters and any pre- and post-filters. This can be useful in conjunction with a hierarchical set of <i>.perltidyrc</i> files to avoid unwanted code tidying. See also <a href="#Skipping-Selected-Sections-of-Code">&quot;Skipping Selected Sections of Code&quot;</a> for a way to avoid tidying specific sections of code.</p>
376
377 </dd>
378 <dt id="i-n---indent-columns-n"><b>-i=n</b>, <b>--indent-columns=n</b></dt>
379 <dd>
380
381 <p>Use n columns per indentation level (default n=4).</p>
382
383 </dd>
384 <dt id="l-n---maximum-line-length-n"><b>-l=n</b>, <b>--maximum-line-length=n</b></dt>
385 <dd>
386
387 <p>The default maximum line length is n=80 characters. Perltidy will try to find line break points to keep lines below this length. However, long quotes and side comments may cause lines to exceed this length.</p>
388
389 <p>The default length of 80 comes from the past when this was the standard CRT screen width. Many programmers prefer to increase this to something like 120.</p>
390
391 <p>Setting <b>-l=0</b> is equivalent to setting <b>-l=(a very large number)</b>. But this is not recommended because, for example, a very long list will be formatted in a single long line.</p>
392
393 </dd>
394 <dt id="vmll---variable-maximum-line-length"><b>-vmll</b>, <b>--variable-maximum-line-length</b></dt>
395 <dd>
396
397 <p>A problem arises using a fixed maximum line length with very deeply nested code and data structures because eventually the amount of leading whitespace used for indicating indentation takes up most or all of the available line width, leaving little or no space for the actual code or data. One solution is to use a very long line length. Another solution is to use the <b>-vmll</b> flag, which basically tells perltidy to ignore leading whitespace when measuring the line length.</p>
398
399 <p>To be precise, when the <b>-vmll</b> parameter is set, the maximum line length of a line of code will be M+L*I, where</p>
400
401 <pre><code>      M is the value of --maximum-line-length=M (-l=M), default 80,
402       I is the value of --indent-columns=I (-i=I), default 4,
403       L is the indentation level of the line of code</code></pre>
404
405 <p>When this flag is set, the choice of breakpoints for a block of code should be essentially independent of its nesting depth. However, the absolute line lengths, including leading whitespace, can still be arbitrarily large. This problem can be avoided by including the next parameter.</p>
406
407 <p>The default is not to do this (<b>-nvmll</b>).</p>
408
409 </dd>
410 <dt id="wc-n---whitespace-cycle-n"><b>-wc=n</b>, <b>--whitespace-cycle=n</b></dt>
411 <dd>
412
413 <p>This flag also addresses problems with very deeply nested code and data structures. When the nesting depth exceeds the value <b>n</b> the leading whitespace will be reduced and start at a depth of 1 again. The result is that blocks of code will shift back to the left rather than moving arbitrarily far to the right. This occurs cyclically to any depth.</p>
414
415 <p>For example if one level of indentation equals 4 spaces (<b>-i=4</b>, the default), and one uses <b>-wc=15</b>, then if the leading whitespace on a line exceeds about 4*15=60 spaces it will be reduced back to 4*1=4 spaces and continue increasing from there. If the whitespace never exceeds this limit the formatting remains unchanged.</p>
416
417 <p>The combination of <b>-vmll</b> and <b>-wc=n</b> provides a solution to the problem of displaying arbitrarily deep data structures and code in a finite window, although <b>-wc=n</b> may of course be used without <b>-vmll</b>.</p>
418
419 <p>The default is not to use this, which can also be indicated using <b>-wc=0</b>.</p>
420
421 </dd>
422 <dt id="Tabs"><b>Tabs</b></dt>
423 <dd>
424
425 <p>Using tab characters will almost certainly lead to future portability and maintenance problems, so the default and recommendation is not to use them. For those who prefer tabs, however, there are two different options.</p>
426
427 <p>Except for possibly introducing tab indentation characters, as outlined below, perltidy does not introduce any tab characters into your file, and it removes any tabs from the code (unless requested not to do so with <b>-fws</b>). If you have any tabs in your comments, quotes, or here-documents, they will remain.</p>
428
429 <dl>
430
431 <dt id="et-n---entab-leading-whitespace"><b>-et=n</b>, <b>--entab-leading-whitespace</b></dt>
432 <dd>
433
434 <p>This flag causes each <b>n</b> initial space characters to be replaced by one tab character.</p>
435
436 <p>The value of the integer <b>n</b> can be any value but can be coordinated with the number of spaces used for intentation. For example, <b>-et=4 -ci=4 -i=4</b> will produce one tab for each indentation level and and one for each continuation indentation level. You may want to coordinate the value of <b>n</b> with what your display software assumes for the spacing of a tab.</p>
437
438 </dd>
439 <dt id="t---tabs"><b>-t</b>, <b>--tabs</b></dt>
440 <dd>
441
442 <p>This flag causes one leading tab character to be inserted for each level of indentation. Certain other features are incompatible with this option, and if these options are also given, then a warning message will be issued and this flag will be unset. One example is the <b>-lp</b> option. This flag is retained for backwards compatibility, but if you use tabs, the <b>-et=n</b> flag is recommended.</p>
443
444 </dd>
445 <dt id="dt-n---default-tabsize-n"><b>-dt=n</b>, <b>--default-tabsize=n</b></dt>
446 <dd>
447
448 <p>If the first line of code passed to perltidy contains leading tabs but no tab scheme is specified for the output stream then perltidy must guess how many spaces correspond to each leading tab. This number of spaces <b>n</b> corresponding to each leading tab of the input stream may be specified with <b>-dt=n</b>. The default is <b>n=8</b>.</p>
449
450 <p>This flag has no effect if a tab scheme is specified for the output stream, because then the input stream is assumed to use the same tab scheme and indentation spaces as for the output stream (any other assumption would lead to unstable editing).</p>
451
452 </dd>
453 </dl>
454
455 </dd>
456 <dt id="xs---extended-syntax"><b>-xs</b>, <b>--extended-syntax</b></dt>
457 <dd>
458
459 <p>A problem with formatting Perl code is that some modules can introduce new syntax. This flag allows perltidy to handle certain common extensions to the standard syntax without complaint.</p>
460
461 <p>For example, without this flag a structure such as the following would generate a syntax error and the braces would not be balanced:</p>
462
463 <pre><code>    method deposit( Num $amount) {
464         $self-&gt;balance( $self-&gt;balance + $amount );
465     }</code></pre>
466
467 <p>For one of the extensions, module Switch::Plain, colons are marked as labels. If you use this module, you may want to also use the <b>--nooutdent-labels</b> flag to prevent lines such as &#39;default:&#39; from being outdented.</p>
468
469 <p>This flag is enabled by default but it can be deactivated with <b>-nxs</b>. Probably the only reason to deactivate this flag is to generate more diagnostic messages when debugging a script.</p>
470
471 <p>For another method of handling extended syntax see the section <a href="#Skipping-Selected-Sections-of-Code">&quot;Skipping Selected Sections of Code&quot;</a>.</p>
472
473 </dd>
474 <dt id="io---indent-only"><b>-io</b>, <b>--indent-only</b></dt>
475 <dd>
476
477 <p>This flag is used to deactivate all whitespace and line break changes within non-blank lines of code. When it is in effect, the only change to the script will be to the indentation and to the number of blank lines. And any flags controlling whitespace and newlines will be ignored. You might want to use this if you are perfectly happy with your whitespace and line breaks, and merely want perltidy to handle the indentation. (This also speeds up perltidy by well over a factor of two, so it might be useful when perltidy is merely being used to help find a brace error in a large script).</p>
478
479 <p>Setting this flag is equivalent to setting <b>--freeze-newlines</b> and <b>--freeze-whitespace</b>.</p>
480
481 <p>If you also want to keep your existing blank lines exactly as they are, you can add <b>--freeze-blank-lines</b>.</p>
482
483 <p>With this option perltidy is still free to modify the indenting (and outdenting) of code and comments as it normally would. If you also want to prevent long comment lines from being outdented, you can add either <b>-noll</b> or <b>-l=0</b>.</p>
484
485 <p>Setting this flag will prevent perltidy from doing any special operations on closing side comments. You may still delete all side comments however when this flag is in effect.</p>
486
487 </dd>
488 <dt id="enc-s---character-encoding-s"><b>-enc=s</b>, <b>--character-encoding=s</b></dt>
489 <dd>
490
491 <p>This flag indicates if the input data stream use a character encoding. Perltidy does not look for the encoding directives in the soure stream, such as <b>use utf8</b>, and instead relies on this flag to determine the encoding. (Note that perltidy often works on snippets of code rather than complete files so it cannot rely on <b>use utf8</b> directives).</p>
492
493 <p>The possible values for <b>s</b> are:</p>
494
495 <pre><code> -enc=none if no encoding is used, or
496  -enc=utf8 for encoding in utf8
497  -enc=guess if perltidy should guess between these two possibilities.</code></pre>
498
499 <p>The value <b>none</b> causes the stream to be processed without special encoding assumptions. This is appropriate for files which are written in single-byte character encodings such as latin-1.</p>
500
501 <p>The value <b>utf8</b> causes the stream to be read and written as UTF-8. If the input stream cannot be decoded with this encoding then processing is not done.</p>
502
503 <p>The value <b>guess</b> tells perltidy to guess between either utf8 encoding or no encoding (meaning one character per byte). The <b>guess</b> option uses the Encode::Guess module which has been found to be reliable at detecting if a file is encoded in utf8 or not.</p>
504
505 <p>The current default is <b>guess</b>.</p>
506
507 <p>The abbreviations <b>-utf8</b> or <b>-UTF8</b> are equivalent to <b>-enc=utf8</b>, and the abbreviation <b>-guess</b> is equivalent to <b>-enc=guess</b>. So to process a file named <b>file.pl</b> which is encoded in UTF-8 you can use:</p>
508
509 <pre><code>   perltidy -utf8 file.pl</code></pre>
510
511 <p>or</p>
512
513 <pre><code>   perltidy -guess file.pl</code></pre>
514
515 <p>or simply</p>
516
517 <pre><code>   perltidy file.pl</code></pre>
518
519 <p>since <b>-guess</b> is the default.</p>
520
521 <p>To process files with an encoding other than UTF-8, it would be necessary to write a short program which calls the Perl::Tidy module with some pre- and post-processing to handle decoding and encoding.</p>
522
523 </dd>
524 <dt id="eos-s---encode-output-strings-s"><b>-eos=s</b>, <b>--encode-output-strings=s</b></dt>
525 <dd>
526
527 <p>This flag has been added to resolve an issue involving the interface between Perl::Tidy and calling programs, and in particular <b>Code::TidyAll (tidyall)</b>. By default Perl::Tidy returns unencoded strings to the calling program, but some programs expect encoded strings. Setting this flag causes Perl::Tidy to return encoded output strings which it decoded. For some background information see <a href="https://github.com/perltidy/perltidy/issues/83">https://github.com/perltidy/perltidy/issues/83</a> and <a href="https://github.com/houseabsolute/perl-code-tidyall/issues/84">https://github.com/houseabsolute/perl-code-tidyall/issues/84</a>.</p>
528
529 <p>If you only run the <b>perltidy</b> binary this flag has no effect.</p>
530
531 <p>If you use <b>tidyall</b> with encoded files and encounter irregularities such as <b>wide character</b> messages you should set this flag.</p>
532
533 <p>Additional information can be found in the man pages for the <b>Perl::Tidy</b> module.</p>
534
535 </dd>
536 <dt id="gcs---use-unicode-gcstring"><b>-gcs</b>, <b>--use-unicode-gcstring</b></dt>
537 <dd>
538
539 <p>This flag controls whether or not perltidy may use module Unicode::GCString to obtain accurate display widths of wide characters. The default is <b>--nouse-unicode-gcstring</b>.</p>
540
541 <p>If this flag is set, and text is encoded, perltidy will look for the module Unicode::GCString and, if found, will use it to obtain character display widths. This can improve displayed vertical alignment for files with wide characters. It is a nice feature but it is off by default to avoid conflicting formatting when there are multiple developers. Perltidy installation does not require Unicode::GCString, so users wanting to use this feature need set this flag and also to install Unicode::GCString separately.</p>
542
543 <p>If this flag is set and perltidy does not find module Unicode::GCString, a warning message will be produced and processing will continue but without the potential benefit provided by the module.</p>
544
545 <p>Also note that actual vertical alignment depends upon the fonts used by the text display software, so vertical alignment may not be optimal even when Unicode::GCString is used.</p>
546
547 </dd>
548 <dt id="ole-s---output-line-ending-s"><b>-ole=s</b>, <b>--output-line-ending=s</b></dt>
549 <dd>
550
551 <p>where s=<code>win</code>, <code>dos</code>, <code>unix</code>, or <code>mac</code>. This flag tells perltidy to output line endings for a specific system. Normally, perltidy writes files with the line separator character of the host system. The <code>win</code> and <code>dos</code> flags have an identical result.</p>
552
553 </dd>
554 <dt id="ple---preserve-line-endings"><b>-ple</b>, <b>--preserve-line-endings</b></dt>
555 <dd>
556
557 <p>This flag tells perltidy to write its output files with the same line endings as the input file, if possible. It should work for <b>dos</b>, <b>unix</b>, and <b>mac</b> line endings. It will only work if perltidy input comes from a filename (rather than stdin, for example). If perltidy has trouble determining the input file line ending, it will revert to the default behavior of using the line ending of the host system.</p>
558
559 </dd>
560 <dt id="atnl---add-terminal-newline"><b>-atnl</b>, <b>--add-terminal-newline</b></dt>
561 <dd>
562
563 <p>This flag, which is enabled by default, allows perltidy to terminate the last line of the output stream with a newline character, regardless of whether or not the input stream was terminated with a newline character. If this flag is negated, with <b>-natnl</b>, then perltidy will add a terminal newline to the the output stream only if the input stream is terminated with a newline.</p>
564
565 <p>Negating this flag may be useful for manipulating one-line scripts intended for use on a command line.</p>
566
567 </dd>
568 <dt id="it-n---iterations-n"><b>-it=n</b>, <b>--iterations=n</b></dt>
569 <dd>
570
571 <p>This flag causes perltidy to do <b>n</b> complete iterations. The reason for this flag is that code beautification is an iterative process and in some cases the output from perltidy can be different if it is applied a second time. For most purposes the default of <b>n=1</b> should be satisfactory. However <b>n=2</b> can be useful when a major style change is being made, or when code is being beautified on check-in to a source code control system. It has been found to be extremely rare for the output to change after 2 iterations. If a value <b>n</b> is greater than 2 is input then a convergence test will be used to stop the iterations as soon as possible, almost always after 2 iterations. See the next item for a simplified iteration control.</p>
572
573 <p>This flag has no effect when perltidy is used to generate html.</p>
574
575 </dd>
576 <dt id="conv---converge"><b>-conv</b>, <b>--converge</b></dt>
577 <dd>
578
579 <p>This flag is equivalent to <b>-it=4</b> and is included to simplify iteration control. For all practical purposes one either does or does not want to be sure that the output is converged, and there is no penalty to using a large iteration limit since perltidy will check for convergence and stop iterating as soon as possible. The default is <b>-nconv</b> (no convergence check). Using <b>-conv</b> will approximately double run time since typically one extra iteration is required to verify convergence. No extra iterations are required if no new line breaks are made, and two extra iterations are occasionally needed when reformatting complex code structures, such as deeply nested ternary statements.</p>
580
581 </dd>
582 </dl>
583
584 <h2 id="Code-Indentation-Control">Code Indentation Control</h2>
585
586 <dl>
587
588 <dt id="ci-n---continuation-indentation-n"><b>-ci=n</b>, <b>--continuation-indentation=n</b></dt>
589 <dd>
590
591 <p>Continuation indentation is extra indentation spaces applied when a long line is broken. The default is n=2, illustrated here:</p>
592
593 <pre><code> my $level =   # -ci=2
594    ( $max_index_to_go &gt;= 0 ) ? $levels_to_go[0] : $last_output_level;</code></pre>
595
596 <p>The same example, with n=0, is a little harder to read:</p>
597
598 <pre><code> my $level =   # -ci=0
599  ( $max_index_to_go &gt;= 0 ) ? $levels_to_go[0] : $last_output_level;</code></pre>
600
601 <p>The value given to <b>-ci</b> is also used by some commands when a small space is required. Examples are commands for outdenting labels, <b>-ola</b>, and control keywords, <b>-okw</b>.</p>
602
603 <p>When default values are not used, it is recommended that either</p>
604
605 <p>(1) the value <b>n</b> given with <b>-ci=n</b> be no more than about one-half of the number of spaces assigned to a full indentation level on the <b>-i=n</b> command, or</p>
606
607 <p>(2) the flag <b>-extended-continuation-indentation</b> is used (see next section).</p>
608
609 </dd>
610 <dt id="xci---extended-continuation-indentation"><b>-xci</b>, <b>--extended-continuation-indentation</b></dt>
611 <dd>
612
613 <p>This flag allows perltidy to use some improvements which have been made to its indentation model. One of the things it does is &quot;extend&quot; continuation indentation deeper into structures, hence the name. The improved indentation is particularly noticeable when the flags <b>-ci=n</b> and <b>-i=n</b> use the same value of <b>n</b>. There are no significant disadvantages to using this flag, but to avoid disturbing existing formatting the default is not to use it, <b>-nxci</b>.</p>
614
615 <p>Please see the section <a href="#pbp---perl-best-practices">&quot;<b>-pbp</b>, <b>--perl-best-practices</b>&quot;</a> for an example of how this flag can improve the formatting of ternary statements. It can also improve indentation of some multi-line qw lists as shown below.</p>
616
617 <pre><code>            # perltidy
618             foreach $color (
619                 qw(
620                 AntiqueWhite3 Bisque1 Bisque2 Bisque3 Bisque4
621                 SlateBlue3 RoyalBlue1 SteelBlue2 DeepSkyBlue3
622                 ),
623                 qw(
624                 LightBlue1 DarkSlateGray1 Aquamarine2 DarkSeaGreen2
625                 SeaGreen1 Yellow1 IndianRed1 IndianRed2 Tan1 Tan4
626                 )
627               )
628
629             # perltidy -xci
630             foreach $color (
631                 qw(
632                     AntiqueWhite3 Bisque1 Bisque2 Bisque3 Bisque4
633                     SlateBlue3 RoyalBlue1 SteelBlue2 DeepSkyBlue3
634                 ),
635                 qw(
636                     LightBlue1 DarkSlateGray1 Aquamarine2 DarkSeaGreen2
637                     SeaGreen1 Yellow1 IndianRed1 IndianRed2 Tan1 Tan4
638                 )
639               )</code></pre>
640
641 </dd>
642 <dt id="sil-n---starting-indentation-level-n"><b>-sil=n</b> <b>--starting-indentation-level=n</b></dt>
643 <dd>
644
645 <p>By default, perltidy examines the input file and tries to determine the starting indentation level. While it is often zero, it may not be zero for a code snippet being sent from an editing session.</p>
646
647 <p>To guess the starting indentation level perltidy simply assumes that indentation scheme used to create the code snippet is the same as is being used for the current perltidy process. This is the only sensible guess that can be made. It should be correct if this is true, but otherwise it probably won&#39;t. For example, if the input script was written with -i=2 and the current peltidy flags have -i=4, the wrong initial indentation will be guessed for a code snippet which has non-zero initial indentation. Likewise, if an entabbing scheme is used in the input script and not in the current process then the guessed indentation will be wrong.</p>
648
649 <p>If the default method does not work correctly, or you want to change the starting level, use <b>-sil=n</b>, to force the starting level to be n.</p>
650
651 </dd>
652 <dt id="List-indentation-using---line-up-parentheses--lp-or---extended--line-up-parentheses--xlp"><b>List indentation</b> using <b>--line-up-parentheses</b>, <b>-lp</b> or <b>--extended--line-up-parentheses</b> , <b>-xlp</b></dt>
653 <dd>
654
655 <p>These flags provide an alternative indentation method for list data. The original flag for this is <b>-lp</b>, but it has some limitations (explained below) which are avoided with the newer <b>-xlp</b> flag. So <b>-xlp</b> is probably the better choice for new work, but the <b>-lp</b> flag is retained to minimize changes to existing formatting. If you enter both <b>-lp</b> and <b>-xlp</b>, then <b>-xlp</b> will be used.</p>
656
657 <p>In the default indentation method perltidy indents lists with 4 spaces, or whatever value is specified with <b>-i=n</b>. Here is a small list formatted in this way:</p>
658
659 <pre><code>    # perltidy (default)
660     @month_of_year = (
661         &#39;Jan&#39;, &#39;Feb&#39;, &#39;Mar&#39;, &#39;Apr&#39;, &#39;May&#39;, &#39;Jun&#39;,
662         &#39;Jul&#39;, &#39;Aug&#39;, &#39;Sep&#39;, &#39;Oct&#39;, &#39;Nov&#39;, &#39;Dec&#39;
663     );</code></pre>
664
665 <p>The <b>-lp</b> or <b>-xlp</b> flags add extra indentation to cause the data to begin past the opening parentheses of a sub call or list, or opening square bracket of an anonymous array, or opening curly brace of an anonymous hash. With this option, the above list would become:</p>
666
667 <pre><code>    # perltidy -lp or -xlp
668     @month_of_year = (
669                        &#39;Jan&#39;, &#39;Feb&#39;, &#39;Mar&#39;, &#39;Apr&#39;, &#39;May&#39;, &#39;Jun&#39;,
670                        &#39;Jul&#39;, &#39;Aug&#39;, &#39;Sep&#39;, &#39;Oct&#39;, &#39;Nov&#39;, &#39;Dec&#39;
671     );</code></pre>
672
673 <p>If the available line length (see <b>-l=n</b> ) does not permit this much space, perltidy will use less. For alternate placement of the closing paren, see the next section.</p>
674
675 <p>These flags have no effect on code BLOCKS, such as if/then/else blocks, which always use whatever is specified with <b>-i=n</b>.</p>
676
677 <p>Some limitiations on these flags are:</p>
678
679 <ul>
680
681 <li><p>A limitation on <b>-lp</b>, but not <b>-xlp</b>, occurs in situations where perltidy does not have complete freedom to choose line breaks. Then it may temporarily revert to its default indentation method. This can occur for example if there are blank lines, block comments, multi-line quotes, or side comments between the opening and closing parens, braces, or brackets. It will also occur if a multi-line anonymous sub occurs within a container since that will impose specific line breaks (such as line breaks after statements).</p>
682
683 </li>
684 <li><p>For both the <b>-lp</b> and <b>-xlp</b> flags, any parameter which significantly restricts the ability of perltidy to choose newlines will conflict with these flags and will cause them to be deactivated. These include <b>-io</b>, <b>-fnl</b>, <b>-nanl</b>, and <b>-ndnl</b>.</p>
685
686 </li>
687 <li><p>The <b>-lp</b> and <b>-xlp</b> options may not be used together with the <b>-t</b> tabs option. They may, however, be used with the <b>-et=n</b> tab method</p>
688
689 </li>
690 </ul>
691
692 <p>There are some potential disadvantages of this indentation method compared to the default method that should be noted:</p>
693
694 <ul>
695
696 <li><p>The available line length can quickly be used up if variable names are long. This can cause deeply nested code to quickly reach the line length limit, and become badly formatted, much sooner than would occur with the default indentation method.</p>
697
698 </li>
699 <li><p>Since the indentation depends on the lengths of variable names, small changes in variable names can cause changes in indentation over many lines in a file. This means that minor name changes can produce significant file differences. This can be annoying and does not occur with the default indentation method.</p>
700
701 </li>
702 </ul>
703
704 <p>Some things that can be done to minimize these problems are:</p>
705
706 <ul>
707
708 <li><p>Increase <b>--maximum-line-length=n</b> above the default <b>n=80</b> characters if necessary.</p>
709
710 </li>
711 <li><p>If you use <b>-xlp</b> then long side comments can limit the indentation over multiple lines. Consider adding the flag <b>--ignore-side-comment-lengths</b> to prevent this, or minimizing the use of side comments.</p>
712
713 </li>
714 <li><p>Apply this style in a limited way. By default, it applies to all list containers (not just lists in parentheses). The next section describes how to limit this style to, for example, just function calls. The default indentation method will be applied elsewhere.</p>
715
716 </li>
717 </ul>
718
719 </dd>
720 <dt id="lpil-s---line-up-parentheses-inclusion-list-and--lpxl-s---line-up-parentheses-exclusion-list"><b>-lpil=s</b>, <b>--line-up-parentheses-inclusion-list</b> and <b>-lpxl=s</b>, <b>--line-up-parentheses-exclusion-list</b></dt>
721 <dd>
722
723 <p>The following discussion is written for <b>-lp</b> but applies equally to the newer <b>-xlp</b> version. By default, the <b>-lp</b> flag applies to as many containers as possible. The set of containers to which the <b>-lp</b> style applies can be reduced by either one of these two flags:</p>
724
725 <p>Use <b>-lpil=s</b> to specify the containers to which <b>-lp</b> applies, or</p>
726
727 <p>use <b>-lpxl=s</b> to specify the containers to which <b>-lp</b> does NOT apply.</p>
728
729 <p>Only one of these two flags may be used. Both flags can achieve the same result, but the <b>-lpil=s</b> flag is much easier to describe and use and is recommended. The <b>-lpxl=s</b> flag was the original implementation and is only retained for backwards compatibility.</p>
730
731 <p>This list <b>s</b> for these parametes is a string with space-separated items. Each item consists of up to three pieces of information in this order: (1) an optional letter code (2) a required container type, and (3) an optional numeric code.</p>
732
733 <p>The only required piece of information is a container type, which is one of &#39;(&#39;, &#39;[&#39;, or &#39;{&#39;. For example the string</p>
734
735 <pre><code>  -lpil=&#39;(&#39;</code></pre>
736
737 <p>means use -lp formatting only on lists within parentheses, not lists in square-bracets or braces. The same thing could alternatively be specified with</p>
738
739 <pre><code>  -lpxl = &#39;[ {&#39;</code></pre>
740
741 <p>which says to exclude lists within square-brackets and braces. So what remains is lists within parentheses.</p>
742
743 <p>A second optional item of information which can be given for parentheses is an alphanumeric letter which is used to limit the selection further depending on the type of token immediately before the paren. The possible letters are currently &#39;k&#39;, &#39;K&#39;, &#39;f&#39;, &#39;F&#39;, &#39;w&#39;, and &#39;W&#39;, with these meanings for matching whatever precedes an opening paren:</p>
744
745 <pre><code> &#39;k&#39; matches if the previous nonblank token is a perl builtin keyword (such as &#39;if&#39;, &#39;while&#39;),
746  &#39;K&#39; matches if &#39;k&#39; does not, meaning that the previous token is not a keyword.
747  &#39;f&#39; matches if the previous token is a function other than a keyword.
748  &#39;F&#39; matches if &#39;f&#39; does not.
749  &#39;w&#39; matches if either &#39;k&#39; or &#39;f&#39; match.
750  &#39;W&#39; matches if &#39;w&#39; does not.</code></pre>
751
752 <p>For example:</p>
753
754 <pre><code>  -lpil = &#39;f(&#39;</code></pre>
755
756 <p>means only apply -lp to function calls, and</p>
757
758 <pre><code>  -lpil = &#39;w(&#39;</code></pre>
759
760 <p>means only apply -lp to parenthesized lists which follow a function or a keyword.</p>
761
762 <p>This last example could alternatively be written using the <b>-lpxl=s</b> flag as</p>
763
764 <pre><code>  -lpxl = &#39;[ { W(&#39;</code></pre>
765
766 <p>which says exclude <b>-lp</b> for lists within square-brackets, braces, and parens NOT preceded by a keyword or function. Clearly, the <b>-lpil=s</b> method is easier to understand.</p>
767
768 <p>An optional numeric code may follow any of the container types to further refine the selection based on container contents. The numeric codes are:</p>
769
770 <pre><code>  &#39;0&#39; or blank: no check on contents is made
771   &#39;1&#39; exclude B&lt;-lp&gt; unless the contents is a simple list without sublists
772   &#39;2&#39; exclude B&lt;-lp&gt; unless the contents is a simple list without sublists, without
773       code blocks, and without ternary operators</code></pre>
774
775 <p>For example,</p>
776
777 <pre><code>  -lpil = &#39;f(2&#39;</code></pre>
778
779 <p>means only apply -lp to function call lists which do not contain any sublists, code blocks or ternary expressions.</p>
780
781 </dd>
782 <dt id="cti-n---closing-token-indentation"><b>-cti=n</b>, <b>--closing-token-indentation</b></dt>
783 <dd>
784
785 <p>The <b>-cti=n</b> flag controls the indentation of a line beginning with a <code>)</code>, <code>]</code>, or a non-block <code>}</code>. Such a line receives:</p>
786
787 <pre><code> -cti = 0 no extra indentation (default)
788  -cti = 1 extra indentation such that the closing token
789         aligns with its opening token.
790  -cti = 2 one extra indentation level if the line looks like:
791         );  or  ];  or  };
792  -cti = 3 one extra indentation level always</code></pre>
793
794 <p>The flags <b>-cti=1</b> and <b>-cti=2</b> work well with the <b>-lp</b> flag (previous section).</p>
795
796 <pre><code>    # perltidy -lp -cti=1
797     @month_of_year = (
798                        &#39;Jan&#39;, &#39;Feb&#39;, &#39;Mar&#39;, &#39;Apr&#39;, &#39;May&#39;, &#39;Jun&#39;,
799                        &#39;Jul&#39;, &#39;Aug&#39;, &#39;Sep&#39;, &#39;Oct&#39;, &#39;Nov&#39;, &#39;Dec&#39;
800                      );
801
802     # perltidy -lp -cti=2
803     @month_of_year = (
804                        &#39;Jan&#39;, &#39;Feb&#39;, &#39;Mar&#39;, &#39;Apr&#39;, &#39;May&#39;, &#39;Jun&#39;,
805                        &#39;Jul&#39;, &#39;Aug&#39;, &#39;Sep&#39;, &#39;Oct&#39;, &#39;Nov&#39;, &#39;Dec&#39;
806                        );</code></pre>
807
808 <p>These flags are merely hints to the formatter and they may not always be followed. In particular, if -lp is not being used, the indentation for <b>cti=1</b> is constrained to be no more than one indentation level.</p>
809
810 <p>If desired, this control can be applied independently to each of the closing container token types. In fact, <b>-cti=n</b> is merely an abbreviation for <b>-cpi=n -csbi=n -cbi=n</b>, where: <b>-cpi</b> or <b>--closing-paren-indentation</b> controls <b>)</b>&#39;s, <b>-csbi</b> or <b>--closing-square-bracket-indentation</b> controls <b>]</b>&#39;s, <b>-cbi</b> or <b>--closing-brace-indentation</b> controls non-block <b>}</b>&#39;s.</p>
811
812 </dd>
813 <dt id="icp---indent-closing-paren"><b>-icp</b>, <b>--indent-closing-paren</b></dt>
814 <dd>
815
816 <p>The <b>-icp</b> flag is equivalent to <b>-cti=2</b>, described in the previous section. The <b>-nicp</b> flag is equivalent <b>-cti=0</b>. They are included for backwards compatibility.</p>
817
818 </dd>
819 <dt id="icb---indent-closing-brace"><b>-icb</b>, <b>--indent-closing-brace</b></dt>
820 <dd>
821
822 <p>The <b>-icb</b> option gives one extra level of indentation to a brace which terminates a code block . For example,</p>
823
824 <pre><code>        if ($task) {
825             yyy();
826             }    # -icb
827         else {
828             zzz();
829             }</code></pre>
830
831 <p>The default is not to do this, indicated by <b>-nicb</b>.</p>
832
833 </dd>
834 <dt id="nib---non-indenting-braces"><b>-nib</b>, <b>--non-indenting-braces</b></dt>
835 <dd>
836
837 <p>Normally, lines of code contained within a pair of block braces receive one additional level of indentation. This flag, which is enabled by default, causes perltidy to look for opening block braces which are followed by a special side comment. This special side comment is <b>#&lt;&lt;&lt;</b> by default. If found, the code between this opening brace and its corresponding closing brace will not be given the normal extra indentation level. For example:</p>
838
839 <pre><code>            { #&lt;&lt;&lt;   a closure to contain lexical vars
840
841             my $var;  # this line does not get one level of indentation
842             ...
843
844             }
845
846             # this line does not &#39;see&#39; $var;</code></pre>
847
848 <p>This can be useful, for example, when combining code from different files. Different sections of code can be placed within braces to keep their lexical variables from being visible to the end of the file. To keep the new braces from causing all of their contained code to be indented if you run perltidy, and possibly introducing new line breaks in long lines, you can mark the opening braces with this special side comment.</p>
849
850 <p>Only the opening brace needs to be marked, since perltidy knows where the closing brace is. Braces contained within marked braces may also be marked as non-indenting.</p>
851
852 <p>If your code happens to have some opening braces followed by &#39;#&lt;&lt;&lt;&#39;, and you don&#39;t want this behavior, you can use <b>-nnib</b> to deactivate it. To make it easy to remember, the default string is the same as the string for starting a <b>format-skipping</b> section. There is no confusion because in that case it is for a block comment rather than a side-comment.</p>
853
854 <p>The special side comment can be changed with the next parameter.</p>
855
856 </dd>
857 <dt id="nibp-s---non-indenting-brace-prefix-s"><b>-nibp=s</b>, <b>--non-indenting-brace-prefix=s</b></dt>
858 <dd>
859
860 <p>The <b>-nibp=string</b> parameter may be used to change the marker for non-indenting braces. The default is equivalent to -nibp=&#39;#&lt;&lt;&lt;&#39;. The string that you enter must begin with a # and should be in quotes as necessary to get past the command shell of your system. This string is the leading text of a regex pattern that is constructed by appending pre-pending a &#39;^&#39; and appending a&#39;\s&#39;, so you must also include backslashes for characters to be taken literally rather than as patterns.</p>
861
862 <p>For example, to match the side comment &#39;#++&#39;, the parameter would be</p>
863
864 <pre><code>  -nibp=&#39;#\+\+&#39;</code></pre>
865
866 </dd>
867 <dt id="olq---outdent-long-quotes"><b>-olq</b>, <b>--outdent-long-quotes</b></dt>
868 <dd>
869
870 <p>When <b>-olq</b> is set, lines which is a quoted string longer than the value <b>maximum-line-length</b> will have their indentation removed to make them more readable. This is the default. To prevent such out-denting, use <b>-nolq</b> or <b>--nooutdent-long-lines</b>.</p>
871
872 </dd>
873 <dt id="oll---outdent-long-lines"><b>-oll</b>, <b>--outdent-long-lines</b></dt>
874 <dd>
875
876 <p>This command is equivalent to <b>--outdent-long-quotes</b> and <b>--outdent-long-comments</b>, and it is included for compatibility with previous versions of perltidy. The negation of this also works, <b>-noll</b> or <b>--nooutdent-long-lines</b>, and is equivalent to setting <b>-nolq</b> and <b>-nolc</b>.</p>
877
878 </dd>
879 <dt id="Outdenting-Labels:--ola---outdent-labels"><b>Outdenting Labels:</b> <b>-ola</b>, <b>--outdent-labels</b></dt>
880 <dd>
881
882 <p>This command will cause labels to be outdented by 2 spaces (or whatever <b>-ci</b> has been set to), if possible. This is the default. For example:</p>
883
884 <pre><code>        my $i;
885       LOOP: while ( $i = &lt;FOTOS&gt; ) {
886             chomp($i);
887             next unless $i;
888             fixit($i);
889         }</code></pre>
890
891 <p>Use <b>-nola</b> to not outdent labels. To control line breaks after labels see <a href="#bal-n---break-after-labels-n">&quot;bal=n, --break-after-labels=n&quot;</a>.</p>
892
893 </dd>
894 <dt id="Outdenting-Keywords"><b>Outdenting Keywords</b></dt>
895 <dd>
896
897 <dl>
898
899 <dt id="okw---outdent-keywords"><b>-okw</b>, <b>--outdent-keywords</b></dt>
900 <dd>
901
902 <p>The command <b>-okw</b> will cause certain leading control keywords to be outdented by 2 spaces (or whatever <b>-ci</b> has been set to), if possible. By default, these keywords are <code>redo</code>, <code>next</code>, <code>last</code>, <code>goto</code>, and <code>return</code>. The intention is to make these control keywords easier to see. To change this list of keywords being outdented, see the next section.</p>
903
904 <p>For example, using <code>perltidy -okw</code> on the previous example gives:</p>
905
906 <pre><code>        my $i;
907       LOOP: while ( $i = &lt;FOTOS&gt; ) {
908             chomp($i);
909           next unless $i;
910             fixit($i);
911         }</code></pre>
912
913 <p>The default is not to do this.</p>
914
915 </dd>
916 <dt id="Specifying-Outdented-Keywords:--okwl-string---outdent-keyword-list-string"><b>Specifying Outdented Keywords:</b> <b>-okwl=string</b>, <b>--outdent-keyword-list=string</b></dt>
917 <dd>
918
919 <p>This command can be used to change the keywords which are outdented with the <b>-okw</b> command. The parameter <b>string</b> is a required list of perl keywords, which should be placed in quotes if there are more than one. By itself, it does not cause any outdenting to occur, so the <b>-okw</b> command is still required.</p>
920
921 <p>For example, the commands <code>-okwl=&quot;next last redo goto&quot; -okw</code> will cause those four keywords to be outdented. It is probably simplest to place any <b>-okwl</b> command in a <i>.perltidyrc</i> file.</p>
922
923 </dd>
924 </dl>
925
926 </dd>
927 </dl>
928
929 <h2 id="Whitespace-Control">Whitespace Control</h2>
930
931 <p>Whitespace refers to the blank space between variables, operators, and other code tokens.</p>
932
933 <dl>
934
935 <dt id="fws---freeze-whitespace"><b>-fws</b>, <b>--freeze-whitespace</b></dt>
936 <dd>
937
938 <p>This flag causes your original whitespace to remain unchanged, and causes the rest of the whitespace commands in this section, the Code Indentation section, and the Comment Control section to be ignored.</p>
939
940 </dd>
941 <dt id="Tightness-of-curly-braces-parentheses-and-square-brackets"><b>Tightness of curly braces, parentheses, and square brackets</b></dt>
942 <dd>
943
944 <p>Here the term &quot;tightness&quot; will mean the closeness with which pairs of enclosing tokens, such as parentheses, contain the quantities within. A numerical value of 0, 1, or 2 defines the tightness, with 0 being least tight and 2 being most tight. Spaces within containers are always symmetric, so if there is a space after a <code>(</code> then there will be a space before the corresponding <code>)</code>.</p>
945
946 <p>The <b>-pt=n</b> or <b>--paren-tightness=n</b> parameter controls the space within parens. The example below shows the effect of the three possible values, 0, 1, and 2:</p>
947
948 <pre><code> if ( ( my $len_tab = length( $tabstr ) ) &gt; 0 ) {  # -pt=0
949  if ( ( my $len_tab = length($tabstr) ) &gt; 0 ) {    # -pt=1 (default)
950  if ((my $len_tab = length($tabstr)) &gt; 0) {        # -pt=2</code></pre>
951
952 <p>When n is 0, there is always a space to the right of a &#39;(&#39; and to the left of a &#39;)&#39;. For n=2 there is never a space. For n=1, the default, there is a space unless the quantity within the parens is a single token, such as an identifier or quoted string.</p>
953
954 <p>Likewise, the parameter <b>-sbt=n</b> or <b>--square-bracket-tightness=n</b> controls the space within square brackets, as illustrated below.</p>
955
956 <pre><code> $width = $col[ $j + $k ] - $col[ $j ];  # -sbt=0
957  $width = $col[ $j + $k ] - $col[$j];    # -sbt=1 (default)
958  $width = $col[$j + $k] - $col[$j];      # -sbt=2</code></pre>
959
960 <p>Curly braces which do not contain code blocks are controlled by the parameter <b>-bt=n</b> or <b>--brace-tightness=n</b>.</p>
961
962 <pre><code> $obj-&gt;{ $parsed_sql-&gt;{ &#39;table&#39; }[0] };    # -bt=0
963  $obj-&gt;{ $parsed_sql-&gt;{&#39;table&#39;}[0] };      # -bt=1 (default)
964  $obj-&gt;{$parsed_sql-&gt;{&#39;table&#39;}[0]};        # -bt=2</code></pre>
965
966 <p>And finally, curly braces which contain blocks of code are controlled by the parameter <b>-bbt=n</b> or <b>--block-brace-tightness=n</b> as illustrated in the example below.</p>
967
968 <pre><code> %bf = map { $_ =&gt; -M $_ } grep { /\.deb$/ } dirents &#39;.&#39;; # -bbt=0 (default)
969  %bf = map { $_ =&gt; -M $_ } grep {/\.deb$/} dirents &#39;.&#39;;   # -bbt=1
970  %bf = map {$_ =&gt; -M $_} grep {/\.deb$/} dirents &#39;.&#39;;     # -bbt=2</code></pre>
971
972 <p>To simplify input in the case that all of the tightness flags have the same value &lt;n&gt;, the parameter &lt;-act=n&gt; or <b>--all-containers-tightness=n</b> is an abbreviation for the combination &lt;-pt=n -sbt=n -bt=n -bbt=n&gt;.</p>
973
974 </dd>
975 <dt id="tso---tight-secret-operators"><b>-tso</b>, <b>--tight-secret-operators</b></dt>
976 <dd>
977
978 <p>The flag <b>-tso</b> causes certain perl token sequences (secret operators) which might be considered to be a single operator to be formatted &quot;tightly&quot; (without spaces). The operators currently modified by this flag are:</p>
979
980 <pre><code>     0+  +0  ()x!! ~~&lt;&gt;  ,=&gt;   =( )=</code></pre>
981
982 <p>For example the sequence <b>0 +</b>, which converts a string to a number, would be formatted without a space: <b>0+</b> when the <b>-tso</b> flag is set. This flag is off by default.</p>
983
984 </dd>
985 <dt id="sts---space-terminal-semicolon"><b>-sts</b>, <b>--space-terminal-semicolon</b></dt>
986 <dd>
987
988 <p>Some programmers prefer a space before all terminal semicolons. The default is for no such space, and is indicated with <b>-nsts</b> or <b>--nospace-terminal-semicolon</b>.</p>
989
990 <pre><code>        $i = 1 ;     #  -sts
991         $i = 1;      #  -nsts   (default)</code></pre>
992
993 </dd>
994 <dt id="sfs---space-for-semicolon"><b>-sfs</b>, <b>--space-for-semicolon</b></dt>
995 <dd>
996
997 <p>Semicolons within <b>for</b> loops may sometimes be hard to see, particularly when commas are also present. This option places spaces on both sides of these special semicolons, and is the default. Use <b>-nsfs</b> or <b>--nospace-for-semicolon</b> to deactivate it.</p>
998
999 <pre><code> for ( @a = @$ap, $u = shift @a ; @a ; $u = $v ) {  # -sfs (default)
1000  for ( @a = @$ap, $u = shift @a; @a; $u = $v ) {    # -nsfs</code></pre>
1001
1002 </dd>
1003 <dt id="asc---add-semicolons"><b>-asc</b>, <b>--add-semicolons</b></dt>
1004 <dd>
1005
1006 <p>Setting <b>-asc</b> allows perltidy to add any missing optional semicolon at the end of a line which is followed by a closing curly brace on the next line. This is the default, and may be deactivated with <b>-nasc</b> or <b>--noadd-semicolons</b>.</p>
1007
1008 </dd>
1009 <dt id="dsm---delete-semicolons"><b>-dsm</b>, <b>--delete-semicolons</b></dt>
1010 <dd>
1011
1012 <p>Setting <b>-dsm</b> allows perltidy to delete extra semicolons which are simply empty statements. This is the default, and may be deactivated with <b>-ndsm</b> or <b>--nodelete-semicolons</b>. (Such semicolons are not deleted, however, if they would promote a side comment to a block comment).</p>
1013
1014 </dd>
1015 <dt id="aws---add-whitespace"><b>-aws</b>, <b>--add-whitespace</b></dt>
1016 <dd>
1017
1018 <p>Setting this option allows perltidy to add certain whitespace to improve code readability. This is the default. If you do not want any whitespace added, but are willing to have some whitespace deleted, use <b>-naws</b>. (Use <b>-fws</b> to leave whitespace completely unchanged).</p>
1019
1020 </dd>
1021 <dt id="dws---delete-old-whitespace"><b>-dws</b>, <b>--delete-old-whitespace</b></dt>
1022 <dd>
1023
1024 <p>Setting this option allows perltidy to remove some old whitespace between characters, if necessary. This is the default. If you do not want any old whitespace removed, use <b>-ndws</b> or <b>--nodelete-old-whitespace</b>.</p>
1025
1026 </dd>
1027 <dt id="Detailed-whitespace-controls-around-tokens"><b>Detailed whitespace controls around tokens</b></dt>
1028 <dd>
1029
1030 <p>For those who want more detailed control over the whitespace around tokens, there are four parameters which can directly modify the default whitespace rules built into perltidy for any token. They are:</p>
1031
1032 <p><b>-wls=s</b> or <b>--want-left-space=s</b>,</p>
1033
1034 <p><b>-nwls=s</b> or <b>--nowant-left-space=s</b>,</p>
1035
1036 <p><b>-wrs=s</b> or <b>--want-right-space=s</b>,</p>
1037
1038 <p><b>-nwrs=s</b> or <b>--nowant-right-space=s</b>.</p>
1039
1040 <p>These parameters are each followed by a quoted string, <b>s</b>, containing a list of token types. No more than one of each of these parameters should be specified, because repeating a command-line parameter always overwrites the previous one before perltidy ever sees it.</p>
1041
1042 <p>To illustrate how these are used, suppose it is desired that there be no space on either side of the token types <b>= + - / *</b>. The following two parameters would specify this desire:</p>
1043
1044 <pre><code>  -nwls=&quot;= + - / *&quot;    -nwrs=&quot;= + - / *&quot;</code></pre>
1045
1046 <p>(Note that the token types are in quotes, and that they are separated by spaces). With these modified whitespace rules, the following line of math:</p>
1047
1048 <pre><code>  $root = -$b + sqrt( $b * $b - 4. * $a * $c ) / ( 2. * $a );</code></pre>
1049
1050 <p>becomes this:</p>
1051
1052 <pre><code>  $root=-$b+sqrt( $b*$b-4.*$a*$c )/( 2.*$a );</code></pre>
1053
1054 <p>These parameters should be considered to be hints to perltidy rather than fixed rules, because perltidy must try to resolve conflicts that arise between them and all of the other rules that it uses. One conflict that can arise is if, between two tokens, the left token wants a space and the right one doesn&#39;t. In this case, the token not wanting a space takes priority.</p>
1055
1056 <p>It is necessary to have a list of all token types in order to create this type of input. Such a list can be obtained by the command <b>--dump-token-types</b>. Also try the <b>-D</b> flag on a short snippet of code and look at the .DEBUG file to see the tokenization.</p>
1057
1058 <p><b>WARNING</b> Be sure to put these tokens in quotes to avoid having them misinterpreted by your command shell.</p>
1059
1060 </dd>
1061 <dt id="Note1:-Perltidy-does-always-follow-whitespace-controls"><b>Note1: Perltidy does always follow whitespace controls</b></dt>
1062 <dd>
1063
1064 <p>The various parameters controlling whitespace within a program are requests which perltidy follows as well as possible, but there are a number of situations where changing whitespace could change program behavior and is not done. Some of these are obvious; for example, we should not remove the space between the two plus symbols in &#39;$x+ +$y&#39; to avoid creating a &#39;++&#39; operator. Some are more subtle and involve the whitespace around bareword symbols and locations of possible filehandles. For example, consider the problem of formatting the following subroutine:</p>
1065
1066 <pre><code>   sub print_div {
1067       my ($x,$y)=@_;
1068       print $x/$y;
1069    }</code></pre>
1070
1071 <p>Suppose the user requests that / signs have a space to the left but not to the right. Perltidy will refuse to do this, but if this were done the result would be</p>
1072
1073 <pre><code>   sub print_div {
1074        my ($x,$y)=@_;
1075        print $x /$y;
1076    }</code></pre>
1077
1078 <p>If formatted in this way, the program will not run (at least with recent versions of perl) because the $x is taken to be a filehandle and / is assumed to start a quote. In a complex program, there might happen to be a / which terminates the multiline quote without a syntax error, allowing the program to run, but not as intended.</p>
1079
1080 <p>Related issues arise with other binary operator symbols, such as + and -, and in older versions of perl there could be problems with ternary operators. So to avoid changing program behavior, perltidy has the simple rule that whitespace around possible filehandles is left unchanged. Likewise, whitespace around barewords is left unchanged. The reason is that if the barewords are defined in other modules, or in code that has not even been written yet, perltidy will not have seen their prototypes and must treat them cautiously.</p>
1081
1082 <p>In perltidy this is implemented in the tokenizer by marking token following a <b>print</b> keyword as a special type <b>Z</b>. When formatting is being done, whitespace following this token type is generally left unchanged as a precaution against changing program behavior. This is excessively conservative but simple and easy to implement. Keywords which are treated similarly to <b>print</b> include <b>printf</b>, <b>sort</b>, <b>exec</b>, <b>system</b>. Changes in spacing around parameters following these keywords may have to be made manually. For example, the space, or lack of space, after the parameter $foo in the following line will be unchanged in formatting.</p>
1083
1084 <pre><code>   system($foo );
1085    system($foo);</code></pre>
1086
1087 <p>To find if a token is of type <b>Z</b> you can use <b>perltidy -DEBUG</b>. For the first line above the result is</p>
1088
1089 <pre><code>   1: system($foo );
1090    1: kkkkkk{ZZZZb};</code></pre>
1091
1092 <p>which shows that <b>system</b> is type <b>k</b> (keyword) and $foo is type <b>Z</b>.</p>
1093
1094 </dd>
1095 <dt id="Note2:-Perltidys-whitespace-rules-are-not-perfect"><b>Note2: Perltidy&#39;s whitespace rules are not perfect</b></dt>
1096 <dd>
1097
1098 <p>Despite these precautions, it is still possible to introduce syntax errors with some asymmetric whitespace rules, particularly when call parameters are not placed in containing parens or braces. For example, the following two lines will be parsed by perl without a syntax error:</p>
1099
1100 <pre><code>  # original programming, syntax ok
1101   my @newkeys = map $_-$nrecs+@data, @oldkeys;
1102
1103   # perltidy default, syntax ok
1104   my @newkeys = map $_ - $nrecs + @data, @oldkeys;</code></pre>
1105
1106 <p>But the following will give a syntax error:</p>
1107
1108 <pre><code>  # perltidy -nwrs=&#39;-&#39;
1109   my @newkeys = map $_ -$nrecs + @data, @oldkeys;</code></pre>
1110
1111 <p>For another example, the following two lines will be parsed without syntax error:</p>
1112
1113 <pre><code>  # original programming, syntax ok
1114   for my $severity ( reverse $SEVERITY_LOWEST+1 .. $SEVERITY_HIGHEST ) { ...  }
1115
1116   # perltidy default, syntax ok
1117   for my $severity ( reverse $SEVERITY_LOWEST + 1 .. $SEVERITY_HIGHEST ) { ... }</code></pre>
1118
1119 <p>But the following will give a syntax error:</p>
1120
1121 <pre><code>  # perltidy -nwrs=&#39;+&#39;, syntax error:
1122   for my $severity ( reverse $SEVERITY_LOWEST +1 .. $SEVERITY_HIGHEST ) { ... }</code></pre>
1123
1124 <p>To avoid subtle parsing problems like this, it is best to avoid spacing a binary operator asymetrically with a space on the left but not on the right.</p>
1125
1126 </dd>
1127 <dt id="Space-between-specific-keywords-and-opening-paren"><b>Space between specific keywords and opening paren</b></dt>
1128 <dd>
1129
1130 <p>When an opening paren follows a Perl keyword, no space is introduced after the keyword, unless it is (by default) one of these:</p>
1131
1132 <pre><code>   my local our and or xor eq ne if else elsif until unless
1133    while for foreach return switch case given when</code></pre>
1134
1135 <p>These defaults can be modified with two commands:</p>
1136
1137 <p><b>-sak=s</b> or <b>--space-after-keyword=s</b> adds keywords.</p>
1138
1139 <p><b>-nsak=s</b> or <b>--nospace-after-keyword=s</b> removes keywords.</p>
1140
1141 <p>where <b>s</b> is a list of keywords (in quotes if necessary). For example,</p>
1142
1143 <pre><code>  my ( $a, $b, $c ) = @_;    # default
1144   my( $a, $b, $c ) = @_;     # -nsak=&quot;my local our&quot;</code></pre>
1145
1146 <p>The abbreviation <b>-nsak=&#39;*&#39;</b> is equivalent to including all of the keywords in the above list.</p>
1147
1148 <p>When both <b>-nsak=s</b> and <b>-sak=s</b> commands are included, the <b>-nsak=s</b> command is executed first. For example, to have space after only the keywords (my, local, our) you could use <b>-nsak=&quot;*&quot; -sak=&quot;my local our&quot;</b>.</p>
1149
1150 <p>To put a space after all keywords, see the next item.</p>
1151
1152 </dd>
1153 <dt id="Space-between-all-keywords-and-opening-parens"><b>Space between all keywords and opening parens</b></dt>
1154 <dd>
1155
1156 <p>When an opening paren follows a function or keyword, no space is introduced after the keyword except for the keywords noted in the previous item. To always put a space between a function or keyword and its opening paren, use the command:</p>
1157
1158 <p><b>-skp</b> or <b>--space-keyword-paren</b></p>
1159
1160 <p>You may also want to use the flag <b>-sfp</b> (next item) too.</p>
1161
1162 </dd>
1163 <dt id="Space-between-all-function-names-and-opening-parens"><b>Space between all function names and opening parens</b></dt>
1164 <dd>
1165
1166 <p>When an opening paren follows a function the default and recommended formatting is not to introduce a space. To cause a space to be introduced use:</p>
1167
1168 <p><b>-sfp</b> or <b>--space-function-paren</b></p>
1169
1170 <pre><code>  myfunc( $a, $b, $c );    # default
1171   myfunc ( $a, $b, $c );   # -sfp</code></pre>
1172
1173 <p>You will probably also want to use the flag <b>-skp</b> (previous item) too.</p>
1174
1175 <p>The reason this is not recommended is that spacing a function paren can make a program vulnerable to parsing problems by Perl. For example, the following two-line program will run as written but will have a syntax error if reformatted with -sfp:</p>
1176
1177 <pre><code>  if ( -e filename() ) { print &quot;I&#39;m here\n&quot;; }
1178   sub filename { return $0 }</code></pre>
1179
1180 <p>In this particular case the syntax error can be removed if the line order is reversed, so that Perl parses &#39;sub filename&#39; first.</p>
1181
1182 </dd>
1183 <dt id="fpva-or---function-paren-vertical-alignment"><b>-fpva</b> or <b>--function-paren-vertical-alignment</b></dt>
1184 <dd>
1185
1186 <p>A side-effect of using the <b>-sfp</b> flag is that the parens may become vertically aligned. For example,</p>
1187
1188 <pre><code>    # perltidy -sfp
1189     myfun     ( $aaa, $b, $cc );
1190     mylongfun ( $a, $b, $c );</code></pre>
1191
1192 <p>This is the default behavior. To prevent this alignment use <b>-nfpva</b>:</p>
1193
1194 <pre><code>    # perltidy -sfp -nfpva
1195     myfun ( $aaa, $b, $cc );
1196     mylongfun ( $a, $b, $c );</code></pre>
1197
1198 </dd>
1199 <dt id="spp-n-or---space-prototype-paren-n"><b>-spp=n</b> or <b>--space-prototype-paren=n</b></dt>
1200 <dd>
1201
1202 <p>This flag can be used to control whether a function prototype is preceded by a space. For example, the following prototype does not have a space.</p>
1203
1204 <pre><code>      sub usage();</code></pre>
1205
1206 <p>This integer <b>n</b> may have the value 0, 1, or 2 as follows:</p>
1207
1208 <pre><code>    -spp=0 means no space before the paren
1209     -spp=1 means follow the example of the source code [DEFAULT]
1210     -spp=2 means always put a space before the paren</code></pre>
1211
1212 <p>The default is <b>-spp=1</b>, meaning that a space will be used if and only if there is one in the source code. Given the above line of code, the result of applying the different options would be:</p>
1213
1214 <pre><code>        sub usage();    # n=0 [no space]
1215         sub usage();    # n=1 [default; follows input]
1216         sub usage ();   # n=2 [space]</code></pre>
1217
1218 </dd>
1219 <dt id="kpit-n-or---keyword-paren-inner-tightness-n"><b>-kpit=n</b> or <b>--keyword-paren-inner-tightness=n</b></dt>
1220 <dd>
1221
1222 <p>The space inside of an opening paren, which itself follows a certain keyword, can be controlled by this parameter. The space on the inside of the corresponding closing paren will be treated in the same (balanced) manner. This parameter has precedence over any other paren spacing rules. The values of <b>n</b> are as follows:</p>
1223
1224 <pre><code>   -kpit=0 means always put a space (not tight)
1225    -kpit=1 means ignore this parameter [default]
1226    -kpit=2 means never put a space (tight)</code></pre>
1227
1228 <p>To illustrate, the following snippet is shown formatted in three ways:</p>
1229
1230 <pre><code>    if ( seek( DATA, 0, 0 ) ) { ... }    # perltidy (default)
1231     if (seek(DATA, 0, 0)) { ... }        # perltidy -pt=2
1232     if ( seek(DATA, 0, 0) ) { ... }      # perltidy -pt=2 -kpit=0</code></pre>
1233
1234 <p>In the second case the -pt=2 parameter makes all of the parens tight. In the third case the -kpit=0 flag causes the space within the &#39;if&#39; parens to have a space, since &#39;if&#39; is one of the keywords to which the -kpit flag applies by default. The remaining parens are still tight because of the -pt=2 parameter.</p>
1235
1236 <p>The set of keywords to which this parameter applies are by default are:</p>
1237
1238 <pre><code>   if elsif unless while until for foreach</code></pre>
1239
1240 <p>These can be changed with the parameter <b>-kpitl=s</b> described in the next section.</p>
1241
1242 </dd>
1243 <dt id="kpitl-string-or---keyword-paren-inner-tightness-string"><b>-kpitl=string</b> or <b>--keyword-paren-inner-tightness=string</b></dt>
1244 <dd>
1245
1246 <p>This command can be used to change the keywords to which the the <b>-kpit=n</b> command applies. The parameter <b>string</b> is a required list either keywords or functions, which should be placed in quotes if there are more than one. By itself, this parameter does not cause any change in spacing, so the <b>-kpit=n</b> command is still required.</p>
1247
1248 <p>For example, the commands <code>-kpitl=&quot;if else while&quot; -kpit=2</code> will cause the just the spaces inside parens following &#39;if&#39;, &#39;else&#39;, and &#39;while&#39; keywords to follow the tightness value indicated by the <b>-kpit=2</b> flag.</p>
1249
1250 </dd>
1251 <dt id="lop-or---logical-padding"><b>-lop</b> or <b>--logical-padding</b></dt>
1252 <dd>
1253
1254 <p>In the following example some extra space has been inserted on the second line between the two open parens. This extra space is called &quot;logical padding&quot; and is intended to help align similar things vertically in some logical or ternary expressions.</p>
1255
1256 <pre><code>    # perltidy [default formatting]
1257     $same =
1258       (      ( $aP eq $bP )
1259           &amp;&amp; ( $aS eq $bS )
1260           &amp;&amp; ( $aT eq $bT )
1261           &amp;&amp; ( $a-&gt;{&#39;title&#39;} eq $b-&gt;{&#39;title&#39;} )
1262           &amp;&amp; ( $a-&gt;{&#39;href&#39;} eq $b-&gt;{&#39;href&#39;} ) );</code></pre>
1263
1264 <p>Note that this is considered to be a different operation from &quot;vertical alignment&quot; because space at just one line is being adjusted, whereas in &quot;vertical alignment&quot; the spaces at all lines are being adjusted. So it sort of a local version of vertical alignment.</p>
1265
1266 <p>Here is an example involving a ternary operator:</p>
1267
1268 <pre><code>    # perltidy [default formatting]
1269     $bits =
1270         $top &gt; 0xffff ? 32
1271       : $top &gt; 0xff   ? 16
1272       : $top &gt; 1      ? 8
1273       :                 1;</code></pre>
1274
1275 <p>This behavior is controlled with the flag <b>--logical-padding</b>, which is set &#39;on&#39; by default. If it is not desired it can be turned off using <b>--nological-padding</b> or <b>-nlop</b>. The above two examples become, with <b>-nlop</b>:</p>
1276
1277 <pre><code>    # perltidy -nlop
1278     $same =
1279       ( ( $aP eq $bP )
1280           &amp;&amp; ( $aS eq $bS )
1281           &amp;&amp; ( $aT eq $bT )
1282           &amp;&amp; ( $a-&gt;{&#39;title&#39;} eq $b-&gt;{&#39;title&#39;} )
1283           &amp;&amp; ( $a-&gt;{&#39;href&#39;} eq $b-&gt;{&#39;href&#39;} ) );
1284
1285     # perltidy -nlop
1286     $bits =
1287       $top &gt; 0xffff ? 32
1288       : $top &gt; 0xff ? 16
1289       : $top &gt; 1    ? 8
1290       :               1;</code></pre>
1291
1292 </dd>
1293 <dt id="Trimming-whitespace-around-qw-quotes"><b>Trimming whitespace around <code>qw</code> quotes</b></dt>
1294 <dd>
1295
1296 <p><b>-tqw</b> or <b>--trim-qw</b> provide the default behavior of trimming spaces around multi-line <code>qw</code> quotes and indenting them appropriately.</p>
1297
1298 <p><b>-ntqw</b> or <b>--notrim-qw</b> cause leading and trailing whitespace around multi-line <code>qw</code> quotes to be left unchanged. This option will not normally be necessary, but was added for testing purposes, because in some versions of perl, trimming <code>qw</code> quotes changes the syntax tree.</p>
1299
1300 </dd>
1301 <dt id="sbq-n-or---space-backslash-quote-n"><b>-sbq=n</b> or <b>--space-backslash-quote=n</b></dt>
1302 <dd>
1303
1304 <p>lines like</p>
1305
1306 <pre><code>       $str1=\&quot;string1&quot;;
1307        $str2=\&#39;string2&#39;;</code></pre>
1308
1309 <p>can confuse syntax highlighters unless a space is included between the backslash and the single or double quotation mark.</p>
1310
1311 <p>this can be controlled with the value of <b>n</b> as follows:</p>
1312
1313 <pre><code>    -sbq=0 means no space between the backslash and quote
1314     -sbq=1 means follow the example of the source code
1315     -sbq=2 means always put a space between the backslash and quote</code></pre>
1316
1317 <p>The default is <b>-sbq=1</b>, meaning that a space will be used if there is one in the source code.</p>
1318
1319 </dd>
1320 <dt id="Trimming-trailing-whitespace-from-lines-of-POD"><b>Trimming trailing whitespace from lines of POD</b></dt>
1321 <dd>
1322
1323 <p><b>-trp</b> or <b>--trim-pod</b> will remove trailing whitespace from lines of POD. The default is not to do this.</p>
1324
1325 </dd>
1326 </dl>
1327
1328 <h2 id="Comment-Controls">Comment Controls</h2>
1329
1330 <p>Perltidy has a number of ways to control the appearance of both block comments and side comments. The term <b>block comment</b> here refers to a full-line comment, whereas <b>side comment</b> will refer to a comment which appears on a line to the right of some code.</p>
1331
1332 <dl>
1333
1334 <dt id="ibc---indent-block-comments"><b>-ibc</b>, <b>--indent-block-comments</b></dt>
1335 <dd>
1336
1337 <p>Block comments normally look best when they are indented to the same level as the code which follows them. This is the default behavior, but you may use <b>-nibc</b> to keep block comments left-justified. Here is an example:</p>
1338
1339 <pre><code>             # this comment is indented      (-ibc, default)
1340              if ($task) { yyy(); }</code></pre>
1341
1342 <p>The alternative is <b>-nibc</b>:</p>
1343
1344 <pre><code> # this comment is not indented              (-nibc)
1345              if ($task) { yyy(); }</code></pre>
1346
1347 <p>See also the next item, <b>-isbc</b>, as well as <b>-sbc</b>, for other ways to have some indented and some outdented block comments.</p>
1348
1349 </dd>
1350 <dt id="isbc---indent-spaced-block-comments"><b>-isbc</b>, <b>--indent-spaced-block-comments</b></dt>
1351 <dd>
1352
1353 <p>If there is no leading space on the line, then the comment will not be indented, and otherwise it may be.</p>
1354
1355 <p>If both <b>-ibc</b> and <b>-isbc</b> are set, then <b>-isbc</b> takes priority.</p>
1356
1357 </dd>
1358 <dt id="olc---outdent-long-comments"><b>-olc</b>, <b>--outdent-long-comments</b></dt>
1359 <dd>
1360
1361 <p>When <b>-olc</b> is set, lines which are full-line (block) comments longer than the value <b>maximum-line-length</b> will have their indentation removed. This is the default; use <b>-nolc</b> to prevent outdenting.</p>
1362
1363 </dd>
1364 <dt id="msc-n---minimum-space-to-comment-n"><b>-msc=n</b>, <b>--minimum-space-to-comment=n</b></dt>
1365 <dd>
1366
1367 <p>Side comments look best when lined up several spaces to the right of code. Perltidy will try to keep comments at least n spaces to the right. The default is n=4 spaces.</p>
1368
1369 </dd>
1370 <dt id="fpsc-n---fixed-position-side-comment-n"><b>-fpsc=n</b>, <b>--fixed-position-side-comment=n</b></dt>
1371 <dd>
1372
1373 <p>This parameter tells perltidy to line up side comments in column number <b>n</b> whenever possible. The default, n=0, will not do this.</p>
1374
1375 </dd>
1376 <dt id="iscl---ignore-side-comment-lengths"><b>-iscl</b>, <b>--ignore-side-comment-lengths</b></dt>
1377 <dd>
1378
1379 <p>This parameter causes perltidy to ignore the length of side comments when setting line breaks. The default, <b>-niscl</b>, is to include the length of side comments when breaking lines to stay within the length prescribed by the <b>-l=n</b> maximum line length parameter. For example, the following long single line would remain intact with -l=80 and -iscl:</p>
1380
1381 <pre><code>     perltidy -l=80 -iscl
1382         $vmsfile =~ s/;[\d\-]*$//; # Clip off version number; we can use a newer version as well</code></pre>
1383
1384 <p>whereas without the -iscl flag the line will be broken:</p>
1385
1386 <pre><code>     perltidy -l=80
1387         $vmsfile =~ s/;[\d\-]*$//
1388           ;    # Clip off version number; we can use a newer version as well</code></pre>
1389
1390 </dd>
1391 <dt id="hsc---hanging-side-comments"><b>-hsc</b>, <b>--hanging-side-comments</b></dt>
1392 <dd>
1393
1394 <p>By default, perltidy tries to identify and align &quot;hanging side comments&quot;, which are something like this:</p>
1395
1396 <pre><code>        my $IGNORE = 0;    # This is a side comment
1397                            # This is a hanging side comment
1398                            # And so is this</code></pre>
1399
1400 <p>A comment is considered to be a hanging side comment if (1) it immediately follows a line with a side comment, or another hanging side comment, and (2) there is some leading whitespace on the line. To deactivate this feature, use <b>-nhsc</b> or <b>--nohanging-side-comments</b>. If block comments are preceded by a blank line, or have no leading whitespace, they will not be mistaken as hanging side comments.</p>
1401
1402 </dd>
1403 <dt id="Closing-Side-Comments"><b>Closing Side Comments</b></dt>
1404 <dd>
1405
1406 <p>A closing side comment is a special comment which perltidy can automatically create and place after the closing brace of a code block. They can be useful for code maintenance and debugging. The command <b>-csc</b> (or <b>--closing-side-comments</b>) adds or updates closing side comments. For example, here is a small code snippet</p>
1407
1408 <pre><code>        sub message {
1409             if ( !defined( $_[0] ) ) {
1410                 print(&quot;Hello, World\n&quot;);
1411             }
1412             else {
1413                 print( $_[0], &quot;\n&quot; );
1414             }
1415         }</code></pre>
1416
1417 <p>And here is the result of processing with <code>perltidy -csc</code>:</p>
1418
1419 <pre><code>        sub message {
1420             if ( !defined( $_[0] ) ) {
1421                 print(&quot;Hello, World\n&quot;);
1422             }
1423             else {
1424                 print( $_[0], &quot;\n&quot; );
1425             }
1426         } ## end sub message</code></pre>
1427
1428 <p>A closing side comment was added for <code>sub message</code> in this case, but not for the <code>if</code> and <code>else</code> blocks, because they were below the 6 line cutoff limit for adding closing side comments. This limit may be changed with the <b>-csci</b> command, described below.</p>
1429
1430 <p>The command <b>-dcsc</b> (or <b>--delete-closing-side-comments</b>) reverses this process and removes these comments.</p>
1431
1432 <p>Several commands are available to modify the behavior of these two basic commands, <b>-csc</b> and <b>-dcsc</b>:</p>
1433
1434 <dl>
1435
1436 <dt id="csci-n-or---closing-side-comment-interval-n"><b>-csci=n</b>, or <b>--closing-side-comment-interval=n</b></dt>
1437 <dd>
1438
1439 <p>where <code>n</code> is the minimum number of lines that a block must have in order for a closing side comment to be added. The default value is <code>n=6</code>. To illustrate:</p>
1440
1441 <pre><code>        # perltidy -csci=2 -csc
1442         sub message {
1443             if ( !defined( $_[0] ) ) {
1444                 print(&quot;Hello, World\n&quot;);
1445             } ## end if ( !defined( $_[0] ))
1446             else {
1447                 print( $_[0], &quot;\n&quot; );
1448             } ## end else [ if ( !defined( $_[0] ))
1449         } ## end sub message</code></pre>
1450
1451 <p>Now the <code>if</code> and <code>else</code> blocks are commented. However, now this has become very cluttered.</p>
1452
1453 </dd>
1454 <dt id="cscp-string-or---closing-side-comment-prefix-string"><b>-cscp=string</b>, or <b>--closing-side-comment-prefix=string</b></dt>
1455 <dd>
1456
1457 <p>where string is the prefix used before the name of the block type. The default prefix, shown above, is <code>## end</code>. This string will be added to closing side comments, and it will also be used to recognize them in order to update, delete, and format them. Any comment identified as a closing side comment will be placed just a single space to the right of its closing brace.</p>
1458
1459 </dd>
1460 <dt id="cscl-string-or---closing-side-comment-list"><b>-cscl=string</b>, or <b>--closing-side-comment-list</b></dt>
1461 <dd>
1462
1463 <p>where <code>string</code> is a list of block types to be tagged with closing side comments. By default, all code block types preceded by a keyword or label (such as <code>if</code>, <code>sub</code>, and so on) will be tagged. The <b>-cscl</b> command changes the default list to be any selected block types; see <a href="#Specifying-Block-Types">&quot;Specifying Block Types&quot;</a>. For example, the following command requests that only <code>sub</code>&#39;s, labels, <code>BEGIN</code>, and <code>END</code> blocks be affected by any <b>-csc</b> or <b>-dcsc</b> operation:</p>
1464
1465 <pre><code>   -cscl=&quot;sub : BEGIN END&quot;</code></pre>
1466
1467 </dd>
1468 <dt id="csct-n-or---closing-side-comment-maximum-text-n"><b>-csct=n</b>, or <b>--closing-side-comment-maximum-text=n</b></dt>
1469 <dd>
1470
1471 <p>The text appended to certain block types, such as an <code>if</code> block, is whatever lies between the keyword introducing the block, such as <code>if</code>, and the opening brace. Since this might be too much text for a side comment, there needs to be a limit, and that is the purpose of this parameter. The default value is <code>n=20</code>, meaning that no additional tokens will be appended to this text after its length reaches 20 characters. Omitted text is indicated with <code>...</code>. (Tokens, including sub names, are never truncated, however, so actual lengths may exceed this). To illustrate, in the above example, the appended text of the first block is <code> ( !defined( $_[0] )...</code>. The existing limit of <code>n=20</code> caused this text to be truncated, as indicated by the <code>...</code>. See the next flag for additional control of the abbreviated text.</p>
1472
1473 </dd>
1474 <dt id="cscb-or---closing-side-comments-balanced"><b>-cscb</b>, or <b>--closing-side-comments-balanced</b></dt>
1475 <dd>
1476
1477 <p>As discussed in the previous item, when the closing-side-comment-maximum-text limit is exceeded the comment text must be truncated. Older versions of perltidy terminated with three dots, and this can still be achieved with -ncscb:</p>
1478
1479 <pre><code>  perltidy -csc -ncscb
1480   } ## end foreach my $foo (sort { $b cmp $a ...</code></pre>
1481
1482 <p>However this causes a problem with editors which cannot recognize comments or are not configured to do so because they cannot &quot;bounce&quot; around in the text correctly. The <b>-cscb</b> flag has been added to help them by appending appropriate balancing structure:</p>
1483
1484 <pre><code>  perltidy -csc -cscb
1485   } ## end foreach my $foo (sort { $b cmp $a ... })</code></pre>
1486
1487 <p>The default is <b>-cscb</b>.</p>
1488
1489 </dd>
1490 <dt id="csce-n-or---closing-side-comment-else-flag-n"><b>-csce=n</b>, or <b>--closing-side-comment-else-flag=n</b></dt>
1491 <dd>
1492
1493 <p>The default, <b>n=0</b>, places the text of the opening <code>if</code> statement after any terminal <code>else</code>.</p>
1494
1495 <p>If <b>n=2</b> is used, then each <code>elsif</code> is also given the text of the opening <code>if</code> statement. Also, an <code>else</code> will include the text of a preceding <code>elsif</code> statement. Note that this may result some long closing side comments.</p>
1496
1497 <p>If <b>n=1</b> is used, the results will be the same as <b>n=2</b> whenever the resulting line length is less than the maximum allowed.</p>
1498
1499 </dd>
1500 <dt id="cscb-or---closing-side-comments-balanced1"><b>-cscb</b>, or <b>--closing-side-comments-balanced</b></dt>
1501 <dd>
1502
1503 <p>When using closing-side-comments, and the closing-side-comment-maximum-text limit is exceeded, then the comment text must be abbreviated. It is terminated with three dots if the <b>-cscb</b> flag is negated:</p>
1504
1505 <pre><code>  perltidy -csc -ncscb
1506   } ## end foreach my $foo (sort { $b cmp $a ...</code></pre>
1507
1508 <p>This causes a problem with older editors which do not recognize comments because they cannot &quot;bounce&quot; around in the text correctly. The <b>-cscb</b> flag tries to help them by appending appropriate terminal balancing structures:</p>
1509
1510 <pre><code>  perltidy -csc -cscb
1511   } ## end foreach my $foo (sort { $b cmp $a ... })</code></pre>
1512
1513 <p>The default is <b>-cscb</b>.</p>
1514
1515 </dd>
1516 <dt id="cscw-or---closing-side-comment-warnings"><b>-cscw</b>, or <b>--closing-side-comment-warnings</b></dt>
1517 <dd>
1518
1519 <p>This parameter is intended to help make the initial transition to the use of closing side comments. It causes two things to happen if a closing side comment replaces an existing, different closing side comment: first, an error message will be issued, and second, the original side comment will be placed alone on a new specially marked comment line for later attention.</p>
1520
1521 <p>The intent is to avoid clobbering existing hand-written side comments which happen to match the pattern of closing side comments. This flag should only be needed on the first run with <b>-csc</b>.</p>
1522
1523 </dd>
1524 </dl>
1525
1526 <p><b>Important Notes on Closing Side Comments:</b></p>
1527
1528 <ul>
1529
1530 <li><p>Closing side comments are only placed on lines terminated with a closing brace. Certain closing styles, such as the use of cuddled elses (<b>-ce</b>), preclude the generation of some closing side comments.</p>
1531
1532 </li>
1533 <li><p>Please note that adding or deleting of closing side comments takes place only through the commands <b>-csc</b> or <b>-dcsc</b>. The other commands, if used, merely modify the behavior of these two commands.</p>
1534
1535 </li>
1536 <li><p>It is recommended that the <b>-cscw</b> flag be used along with <b>-csc</b> on the first use of perltidy on a given file. This will prevent loss of any existing side comment data which happens to have the csc prefix.</p>
1537
1538 </li>
1539 <li><p>Once you use <b>-csc</b>, you should continue to use it so that any closing side comments remain correct as code changes. Otherwise, these comments will become incorrect as the code is updated.</p>
1540
1541 </li>
1542 <li><p>If you edit the closing side comments generated by perltidy, you must also change the prefix to be different from the closing side comment prefix. Otherwise, your edits will be lost when you rerun perltidy with <b>-csc</b>. For example, you could simply change <code>## end</code> to be <code>## End</code>, since the test is case sensitive. You may also want to use the <b>-ssc</b> flag to keep these modified closing side comments spaced the same as actual closing side comments.</p>
1543
1544 </li>
1545 <li><p>Temporarily generating closing side comments is a useful technique for exploring and/or debugging a perl script, especially one written by someone else. You can always remove them with <b>-dcsc</b>.</p>
1546
1547 </li>
1548 </ul>
1549
1550 </dd>
1551 <dt id="Static-Block-Comments"><b>Static Block Comments</b></dt>
1552 <dd>
1553
1554 <p>Static block comments are block comments with a special leading pattern, <code>##</code> by default, which will be treated slightly differently from other block comments. They effectively behave as if they had glue along their left and top edges, because they stick to the left edge and previous line when there is no blank spaces in those places. This option is particularly useful for controlling how commented code is displayed.</p>
1555
1556 <dl>
1557
1558 <dt id="sbc---static-block-comments"><b>-sbc</b>, <b>--static-block-comments</b></dt>
1559 <dd>
1560
1561 <p>When <b>-sbc</b> is used, a block comment with a special leading pattern, <code>##</code> by default, will be treated specially.</p>
1562
1563 <p>Comments so identified are treated as follows:</p>
1564
1565 <ul>
1566
1567 <li><p>If there is no leading space on the line, then the comment will not be indented, and otherwise it may be,</p>
1568
1569 </li>
1570 <li><p>no new blank line will be inserted before such a comment, and</p>
1571
1572 </li>
1573 <li><p>such a comment will never become a hanging side comment.</p>
1574
1575 </li>
1576 </ul>
1577
1578 <p>For example, assuming <code>@month_of_year</code> is left-adjusted:</p>
1579
1580 <pre><code>    @month_of_year = (    # -sbc (default)
1581         &#39;Jan&#39;, &#39;Feb&#39;, &#39;Mar&#39;, &#39;Apr&#39;, &#39;May&#39;, &#39;Jun&#39;, &#39;Jul&#39;, &#39;Aug&#39;, &#39;Sep&#39;, &#39;Oct&#39;,
1582     ##  &#39;Dec&#39;, &#39;Nov&#39;
1583         &#39;Nov&#39;, &#39;Dec&#39;);</code></pre>
1584
1585 <p>Without this convention, the above code would become</p>
1586
1587 <pre><code>    @month_of_year = (   # -nsbc
1588         &#39;Jan&#39;, &#39;Feb&#39;, &#39;Mar&#39;, &#39;Apr&#39;, &#39;May&#39;, &#39;Jun&#39;, &#39;Jul&#39;, &#39;Aug&#39;, &#39;Sep&#39;, &#39;Oct&#39;,
1589
1590         ##  &#39;Dec&#39;, &#39;Nov&#39;
1591         &#39;Nov&#39;, &#39;Dec&#39;
1592     );</code></pre>
1593
1594 <p>which is not as clear. The default is to use <b>-sbc</b>. This may be deactivated with <b>-nsbc</b>.</p>
1595
1596 </dd>
1597 <dt id="sbcp-string---static-block-comment-prefix-string"><b>-sbcp=string</b>, <b>--static-block-comment-prefix=string</b></dt>
1598 <dd>
1599
1600 <p>This parameter defines the prefix used to identify static block comments when the <b>-sbc</b> parameter is set. The default prefix is <code>##</code>, corresponding to <code>-sbcp=##</code>. The prefix is actually part of a perl pattern used to match lines and it must either begin with <code>#</code> or <code>^#</code>. In the first case a prefix ^\s* will be added to match any leading whitespace, while in the second case the pattern will match only comments with no leading whitespace. For example, to identify all comments as static block comments, one would use <code>-sbcp=#</code>. To identify all left-adjusted comments as static block comments, use <code>-sbcp=&#39;^#&#39;</code>.</p>
1601
1602 <p>Please note that <b>-sbcp</b> merely defines the pattern used to identify static block comments; it will not be used unless the switch <b>-sbc</b> is set. Also, please be aware that since this string is used in a perl regular expression which identifies these comments, it must enable a valid regular expression to be formed.</p>
1603
1604 <p>A pattern which can be useful is:</p>
1605
1606 <pre><code>    -sbcp=^#{2,}[^\s#]</code></pre>
1607
1608 <p>This pattern requires a static block comment to have at least one character which is neither a # nor a space. It allows a line containing only &#39;#&#39; characters to be rejected as a static block comment. Such lines are often used at the start and end of header information in subroutines and should not be separated from the intervening comments, which typically begin with just a single &#39;#&#39;.</p>
1609
1610 </dd>
1611 <dt id="osbc---outdent-static-block-comments"><b>-osbc</b>, <b>--outdent-static-block-comments</b></dt>
1612 <dd>
1613
1614 <p>The command <b>-osbc</b> will cause static block comments to be outdented by 2 spaces (or whatever <b>-ci=n</b> has been set to), if possible.</p>
1615
1616 </dd>
1617 </dl>
1618
1619 </dd>
1620 <dt id="Static-Side-Comments"><b>Static Side Comments</b></dt>
1621 <dd>
1622
1623 <p>Static side comments are side comments with a special leading pattern. This option can be useful for controlling how commented code is displayed when it is a side comment.</p>
1624
1625 <dl>
1626
1627 <dt id="ssc---static-side-comments"><b>-ssc</b>, <b>--static-side-comments</b></dt>
1628 <dd>
1629
1630 <p>When <b>-ssc</b> is used, a side comment with a static leading pattern, which is <code>##</code> by default, will be spaced only a single space from previous character, and it will not be vertically aligned with other side comments.</p>
1631
1632 <p>The default is <b>-nssc</b>.</p>
1633
1634 </dd>
1635 <dt id="sscp-string---static-side-comment-prefix-string"><b>-sscp=string</b>, <b>--static-side-comment-prefix=string</b></dt>
1636 <dd>
1637
1638 <p>This parameter defines the prefix used to identify static side comments when the <b>-ssc</b> parameter is set. The default prefix is <code>##</code>, corresponding to <code>-sscp=##</code>.</p>
1639
1640 <p>Please note that <b>-sscp</b> merely defines the pattern used to identify static side comments; it will not be used unless the switch <b>-ssc</b> is set. Also, note that this string is used in a perl regular expression which identifies these comments, so it must enable a valid regular expression to be formed.</p>
1641
1642 </dd>
1643 </dl>
1644
1645 </dd>
1646 </dl>
1647
1648 <h2 id="Skipping-Selected-Sections-of-Code">Skipping Selected Sections of Code</h2>
1649
1650 <p>Selected lines of code may be passed verbatim to the output without any formatting by marking the starting and ending lines with special comments. There are two options for doing this. The first option is called <b>--format-skipping</b> or <b>-fs</b>, and the second option is called <b>--code-skipping</b> or <b>-cs</b>.</p>
1651
1652 <p>In both cases the lines of code will be output without any changes. The difference is that in <b>--format-skipping</b> perltidy will still parse the marked lines of code and check for errors, whereas in <b>--code-skipping</b> perltidy will simply pass the lines to the output without any checking.</p>
1653
1654 <p>Both of these features are enabled by default and are invoked with special comment markers. <b>--format-skipping</b> uses starting and ending markers &#39;#&lt;&lt;&lt;&#39; and &#39;#&gt;&gt;&gt;&#39;, like this:</p>
1655
1656 <pre><code> #&lt;&lt;&lt;  format skipping: do not let perltidy change my nice formatting
1657     my @list = (1,
1658                 1, 1,
1659                 1, 2, 1,
1660                 1, 3, 3, 1,
1661                 1, 4, 6, 4, 1,);
1662  #&gt;&gt;&gt;</code></pre>
1663
1664 <p><b>--code-skipping</b> uses starting and ending markers &#39;#&lt;&lt;V&#39; and &#39;#&gt;&gt;V&#39;, like this:</p>
1665
1666 <pre><code> #&lt;&lt;V  code skipping: perltidy will pass this verbatim without error checking
1667
1668     token ident_digit {
1669         [ [ &lt;?word&gt; | _ | &lt;?digit&gt; ] &lt;?ident_digit&gt;
1670         |   &lt;&#39;&#39;&gt;
1671         ]
1672     };
1673
1674  #&gt;&gt;V</code></pre>
1675
1676 <p>Additional text may appear on the special comment lines provided that it is separated from the marker by at least one space, as in the above examples.</p>
1677
1678 <p>Any number of code-skipping or format-skipping sections may appear in a file. If an opening code-skipping or format-skipping comment is not followed by a corresponding closing comment, then skipping continues to the end of the file. If a closing code-skipping or format-skipping comment appears in a file but does not follow a corresponding opening comment, then it is treated as an ordinary comment without any special meaning.</p>
1679
1680 <p>It is recommended to use <b>--code-skipping</b> only if you need to hide a block of an extended syntax which would produce errors if parsed by perltidy, and use <b>--format-skipping</b> otherwise. This is because the <b>--format-skipping</b> option provides the benefits of error checking, and there are essentially no limitations on which lines to which it can be applied. The <b>--code-skipping</b> option, on the other hand, does not do error checking and its use is more restrictive because the code which remains, after skipping the marked lines, must be syntactically correct code with balanced containers.</p>
1681
1682 <p>These features should be used sparingly to avoid littering code with markers, but they can be helpful for working around occasional problems.</p>
1683
1684 <p>Note that it may be possible to avoid the use of <b>--format-skipping</b> for the specific case of a comma-separated list of values, as in the above example, by simply inserting a blank or comment somewhere between the opening and closing parens. See the section <a href="#Controlling-List-Formatting">&quot;Controlling List Formatting&quot;</a>.</p>
1685
1686 <p>The following sections describe the available controls for these options. They should not normally be needed.</p>
1687
1688 <dl>
1689
1690 <dt id="fs---format-skipping"><b>-fs</b>, <b>--format-skipping</b></dt>
1691 <dd>
1692
1693 <p>As explained above, this flag, which is enabled by default, causes any code between special beginning and ending comment markers to be passed to the output without formatting. The code between the comments is still checked for errors however. The default beginning marker is #&lt;&lt;&lt; and the default ending marker is #&gt;&gt;&gt;.</p>
1694
1695 <p>Format skipping begins when a format skipping beginning comment is seen and continues until a format-skipping ending comment is found.</p>
1696
1697 <p>This feature can be disabled with <b>-nfs</b>. This should not normally be necessary.</p>
1698
1699 </dd>
1700 <dt id="fsb-string---format-skipping-begin-string"><b>-fsb=string</b>, <b>--format-skipping-begin=string</b></dt>
1701 <dd>
1702
1703 <p>This and the next parameter allow the special beginning and ending comments to be changed. However, it is recommended that they only be changed if there is a conflict between the default values and some other use. If they are used, it is recommended that they only be entered in a <b>.perltidyrc</b> file, rather than on a command line. This is because properly escaping these parameters on a command line can be difficult.</p>
1704
1705 <p>If changed comment markers do not appear to be working, use the <b>-log</b> flag and examine the <i>.LOG</i> file to see if and where they are being detected.</p>
1706
1707 <p>The <b>-fsb=string</b> parameter may be used to change the beginning marker for format skipping. The default is equivalent to -fsb=&#39;#&lt;&lt;&lt;&#39;. The string that you enter must begin with a # and should be in quotes as necessary to get past the command shell of your system. It is actually the leading text of a pattern that is constructed by appending a &#39;\s&#39;, so you must also include backslashes for characters to be taken literally rather than as patterns.</p>
1708
1709 <p>Some examples show how example strings become patterns:</p>
1710
1711 <pre><code> -fsb=&#39;#\{\{\{&#39; becomes /^#\{\{\{\s/  which matches  #{{{ but not #{{{{
1712  -fsb=&#39;#\*\*&#39;   becomes /^#\*\*\s/    which matches  #** but not #***
1713  -fsb=&#39;#\*{2,}&#39; becomes /^#\*{2,}\s/  which matches  #** and #*****</code></pre>
1714
1715 </dd>
1716 <dt id="fse-string---format-skipping-end-string"><b>-fse=string</b>, <b>--format-skipping-end=string</b></dt>
1717 <dd>
1718
1719 <p>The <b>-fse=string</b> is the corresponding parameter used to change the ending marker for format skipping. The default is equivalent to -fse=&#39;#&lt;&lt;&lt;&#39;.</p>
1720
1721 <p>The beginning and ending strings may be the same, but it is preferable to make them different for clarity.</p>
1722
1723 </dd>
1724 <dt id="cs---code-skipping"><b>-cs</b>, <b>--code-skipping</b></dt>
1725 <dd>
1726
1727 <p>As explained above, this flag, which is enabled by default, causes any code between special beginning and ending comment markers to be directly passed to the output without any error checking or formatting. Essentially, perltidy treats it as if it were a block of arbitrary text. The default beginning marker is #&lt;&lt;V and the default ending marker is #&gt;&gt;V.</p>
1728
1729 <p>This feature can be disabled with <b>-ncs</b>. This should not normally be necessary.</p>
1730
1731 </dd>
1732 <dt id="csb-string---code-skipping-begin-string"><b>-csb=string</b>, <b>--code-skipping-begin=string</b></dt>
1733 <dd>
1734
1735 <p>This may be used to change the beginning comment for a <b>--code-skipping</b> section, and its use is similar to the <b>-fsb=string</b>. The default is equivalent to -csb=&#39;#&lt;&lt;V&#39;.</p>
1736
1737 </dd>
1738 <dt id="cse-string---code-skipping-end-string"><b>-cse=string</b>, <b>--code-skipping-end=string</b></dt>
1739 <dd>
1740
1741 <p>This may be used to change the ending comment for a <b>--code-skipping</b> section, and its use is similar to the <b>-fse=string</b>. The default is equivalent to -cse=&#39;#&gt;&gt;V&#39;.</p>
1742
1743 </dd>
1744 </dl>
1745
1746 <h2 id="Line-Break-Control">Line Break Control</h2>
1747
1748 <p>The parameters in this section control breaks after non-blank lines of code. Blank lines are controlled separately by parameters in the section <a href="#Blank-Line-Control">&quot;Blank Line Control&quot;</a>.</p>
1749
1750 <dl>
1751
1752 <dt id="fnl---freeze-newlines"><b>-fnl</b>, <b>--freeze-newlines</b></dt>
1753 <dd>
1754
1755 <p>If you do not want any changes to the line breaks within lines of code in your script, set <b>-fnl</b>, and they will remain fixed, and the rest of the commands in this section and sections <a href="#Controlling-List-Formatting">&quot;Controlling List Formatting&quot;</a>, <a href="#Retaining-or-Ignoring-Existing-Line-Breaks">&quot;Retaining or Ignoring Existing Line Breaks&quot;</a>. You may want to use <b>-noll</b> with this.</p>
1756
1757 <p>Note: If you also want to keep your blank lines exactly as they are, you can use the <b>-fbl</b> flag which is described in the section <a href="#Blank-Line-Control">&quot;Blank Line Control&quot;</a>.</p>
1758
1759 </dd>
1760 <dt id="ce---cuddled-else"><b>-ce</b>, <b>--cuddled-else</b></dt>
1761 <dd>
1762
1763 <p>Enable the &quot;cuddled else&quot; style, in which <code>else</code> and <code>elsif</code> are follow immediately after the curly brace closing the previous block. The default is not to use cuddled elses, and is indicated with the flag <b>-nce</b> or <b>--nocuddled-else</b>. Here is a comparison of the alternatives:</p>
1764
1765 <pre><code>  # -ce
1766   if ($task) {
1767       yyy();
1768   } else {
1769       zzz();
1770   }
1771
1772   # -nce (default)
1773   if ($task) {
1774         yyy();
1775   }
1776   else {
1777         zzz();
1778   }</code></pre>
1779
1780 <p>In this example the keyword <b>else</b> is placed on the same line which begins with the preceding closing block brace and is followed by its own opening block brace on the same line. Other keywords and function names which are formatted with this &quot;cuddled&quot; style are <b>elsif</b>, <b>continue</b>, <b>catch</b>, <b>finally</b>.</p>
1781
1782 <p>Other block types can be formatted by specifying their names on a separate parameter <b>-cbl</b>, described in a later section.</p>
1783
1784 <p>Cuddling between a pair of code blocks requires that the closing brace of the first block start a new line. If this block is entirely on one line in the input file, it is necessary to decide if it should be broken to allow cuddling. This decision is controlled by the flag <b>-cbo=n</b> discussed below. The default and recommended value of <b>-cbo=1</b> bases this decision on the first block in the chain. If it spans multiple lines then cuddling is made and continues along the chain, regardless of the sizes of subsequent blocks. Otherwise, short lines remain intact.</p>
1785
1786 <p>So for example, the <b>-ce</b> flag would not have any effect if the above snippet is rewritten as</p>
1787
1788 <pre><code>  if ($task) { yyy() }
1789   else {    zzz() }</code></pre>
1790
1791 <p>If the first block spans multiple lines, then cuddling can be done and will continue for the subsequent blocks in the chain, as illustrated in the previous snippet.</p>
1792
1793 <p>If there are blank lines between cuddled blocks they will be eliminated. If there are comments after the closing brace where cuddling would occur then cuddling will be prevented. If this occurs, cuddling will restart later in the chain if possible.</p>
1794
1795 </dd>
1796 <dt id="cb---cuddled-blocks"><b>-cb</b>, <b>--cuddled-blocks</b></dt>
1797 <dd>
1798
1799 <p>This flag is equivalent to <b>-ce</b>.</p>
1800
1801 </dd>
1802 <dt id="cbl---cuddled-block-list"><b>-cbl</b>, <b>--cuddled-block-list</b></dt>
1803 <dd>
1804
1805 <p>The built-in default cuddled block types are <b>else, elsif, continue, catch, finally</b>.</p>
1806
1807 <p>Additional block types to which the <b>-cuddled-blocks</b> style applies can be defined by this parameter. This parameter is a character string, giving a list of block types separated by commas or spaces. For example, to cuddle code blocks of type sort, map and grep, in addition to the default types, the string could be set to</p>
1808
1809 <pre><code>  -cbl=&quot;sort map grep&quot;</code></pre>
1810
1811 <p>or equivalently</p>
1812
1813 <pre><code>  -cbl=sort,map,grep</code></pre>
1814
1815 <p>Note however that these particular block types are typically short so there might not be much opportunity for the cuddled format style.</p>
1816
1817 <p>Using commas avoids the need to protect spaces with quotes.</p>
1818
1819 <p>As a diagnostic check, the flag <b>--dump-cuddled-block-list</b> or <b>-dcbl</b> can be used to view the hash of values that are generated by this flag.</p>
1820
1821 <p>Finally, note that the <b>-cbl</b> flag by itself merely specifies which blocks are formatted with the cuddled format. It has no effect unless this formatting style is activated with <b>-ce</b>.</p>
1822
1823 </dd>
1824 <dt id="cblx---cuddled-block-list-exclusive"><b>-cblx</b>, <b>--cuddled-block-list-exclusive</b></dt>
1825 <dd>
1826
1827 <p>When cuddled else formatting is selected with <b>-ce</b>, setting this flag causes perltidy to ignore its built-in defaults and rely exclusively on the block types specified on the <b>-cbl</b> flag described in the previous section. For example, to avoid using cuddled <b>catch</b> and <b>finally</b>, which among in the defaults, the following set of parameters could be used:</p>
1828
1829 <pre><code>  perltidy -ce -cbl=&#39;else elsif continue&#39; -cblx</code></pre>
1830
1831 </dd>
1832 <dt id="cbo-n---cuddled-break-option-n"><b>-cbo=n</b>, <b>--cuddled-break-option=n</b></dt>
1833 <dd>
1834
1835 <p>Cuddled formatting is only possible between a pair of code blocks if the closing brace of the first block starts a new line. If a block is encountered which is entirely on a single line, and cuddled formatting is selected, it is necessary to make a decision as to whether or not to &quot;break&quot; the block, meaning to cause it to span multiple lines. This parameter controls that decision. The options are:</p>
1836
1837 <pre><code>   cbo=0  Never force a short block to break.
1838    cbo=1  If the first of a pair of blocks is broken in the input file,
1839           then break the second [DEFAULT].
1840    cbo=2  Break open all blocks for maximal cuddled formatting.</code></pre>
1841
1842 <p>The default and recommended value is <b>cbo=1</b>. With this value, if the starting block of a chain spans multiple lines, then a cascade of breaks will occur for remaining blocks causing the entire chain to be cuddled.</p>
1843
1844 <p>The option <b>cbo=0</b> can produce erratic cuddling if there are numerous one-line blocks.</p>
1845
1846 <p>The option <b>cbo=2</b> produces maximal cuddling but will not allow any short blocks.</p>
1847
1848 </dd>
1849 <dt id="bl---opening-brace-on-new-line-or---brace-left"><b>-bl</b>, <b>--opening-brace-on-new-line</b>, or <b>--brace-left</b></dt>
1850 <dd>
1851
1852 <p>Use the flag <b>-bl</b> to place an opening block brace on a new line:</p>
1853
1854 <pre><code>  if ( $input_file eq &#39;-&#39; )
1855   {
1856       ...
1857   }</code></pre>
1858
1859 <p>By default it applies to all structural blocks except <b>sort map grep eval</b> and anonymous subs.</p>
1860
1861 <p>The default is <b>-nbl</b> which places an opening brace on the same line as the keyword introducing it if possible. For example,</p>
1862
1863 <pre><code>  # default
1864   if ( $input_file eq &#39;-&#39; ) {
1865      ...
1866   }</code></pre>
1867
1868 <p>When <b>-bl</b> is set, the blocks to which this applies can be controlled with the parameters <b>--brace-left-list</b> and <b>-brace-left-exclusion-list</b> described in the next sections.</p>
1869
1870 </dd>
1871 <dt id="bll-s---brace-left-list-s"><b>-bll=s</b>, <b>--brace-left-list=s</b></dt>
1872 <dd>
1873
1874 <p>Use this parameter to change the types of block braces for which the <b>-bl</b> flag applies; see <a href="#Specifying-Block-Types">&quot;Specifying Block Types&quot;</a>. For example, <b>-bll=&#39;if elsif else sub&#39;</b> would apply it to only <code>if/elsif/else</code> and named sub blocks. The default is all blocks, <b>-bll=&#39;*&#39;</b>.</p>
1875
1876 </dd>
1877 <dt id="blxl-s---brace-left-exclusion-list-s"><b>-blxl=s</b>, <b>--brace-left-exclusion-list=s</b></dt>
1878 <dd>
1879
1880 <p>Use this parameter to exclude types of block braces for which the <b>-bl</b> flag applies; see <a href="#Specifying-Block-Types">&quot;Specifying Block Types&quot;</a>. For example, the default settings <b>-bll=&#39;*&#39;</b> and <b>-blxl=&#39;sort map grep eval asub&#39;</b> mean all blocks except <b>sort map grep eval</b> and anonymous sub blocks.</p>
1881
1882 <p>Note that the lists <b>-bll=s</b> and <b>-blxl=s</b> control the behavior of the <b>-bl</b> flag but have no effect unless the <b>-bl</b> flag is set.</p>
1883
1884 </dd>
1885 <dt id="sbl---opening-sub-brace-on-new-line"><b>-sbl</b>, <b>--opening-sub-brace-on-new-line</b></dt>
1886 <dd>
1887
1888 <p>The flag <b>-sbl</b> provides a shortcut way to turn on <b>-bl</b> just for named subs. The same effect can be achieved by turning on <b>-bl</b> with the block list set as <b>-bll=&#39;sub&#39;</b>.</p>
1889
1890 <p>For example,</p>
1891
1892 <pre><code> perltidy -sbl</code></pre>
1893
1894 <p>produces this result:</p>
1895
1896 <pre><code> sub message
1897  {
1898     if (!defined($_[0])) {
1899         print(&quot;Hello, World\n&quot;);
1900     }
1901     else {
1902         print($_[0], &quot;\n&quot;);
1903     }
1904  }</code></pre>
1905
1906 <p>This flag is negated with <b>-nsbl</b>, which is the default.</p>
1907
1908 </dd>
1909 <dt id="asbl---opening-anonymous-sub-brace-on-new-line"><b>-asbl</b>, <b>--opening-anonymous-sub-brace-on-new-line</b></dt>
1910 <dd>
1911
1912 <p>The flag <b>-asbl</b> is like the <b>-sbl</b> flag except that it applies to anonymous sub&#39;s instead of named subs. For example</p>
1913
1914 <pre><code> perltidy -asbl</code></pre>
1915
1916 <p>produces this result:</p>
1917
1918 <pre><code> $a = sub
1919  {
1920      if ( !defined( $_[0] ) ) {
1921          print(&quot;Hello, World\n&quot;);
1922      }
1923      else {
1924          print( $_[0], &quot;\n&quot; );
1925      }
1926  };</code></pre>
1927
1928 <p>This flag is negated with <b>-nasbl</b>, and the default is <b>-nasbl</b>.</p>
1929
1930 </dd>
1931 <dt id="bli---brace-left-and-indent"><b>-bli</b>, <b>--brace-left-and-indent</b></dt>
1932 <dd>
1933
1934 <p>The flag <b>-bli</b> is similar to the <b>-bl</b> flag but in addition it causes one unit of continuation indentation ( see <b>-ci</b> ) to be placed before an opening and closing block braces.</p>
1935
1936 <p>For example, perltidy -bli gives</p>
1937
1938 <pre><code>        if ( $input_file eq &#39;-&#39; )
1939           {
1940             important_function();
1941           }</code></pre>
1942
1943 <p>By default, this extra indentation occurs for block types: <b>if</b>, <b>elsif</b>, <b>else</b>, <b>unless</b>, <b>while</b>, <b>for</b>, <b>foreach</b>, <b>do</b>, and also <b>named subs</b> and blocks preceded by a <b>label</b>. The next item shows how to change this.</p>
1944
1945 <p><b>Note</b>: The <b>-bli</b> flag is similar to the <b>-bl</b> flag, with the difference being that braces get indented. But these two flags are implemented independently, and have different default settings for historical reasons. If desired, a mixture of effects can be achieved if desired by turning them both on with different <b>-list</b> settings. In the event that both settings are selected for a certain block type, the <b>-bli</b> style has priority.</p>
1946
1947 </dd>
1948 <dt id="blil-s---brace-left-and-indent-list-s"><b>-blil=s</b>, <b>--brace-left-and-indent-list=s</b></dt>
1949 <dd>
1950
1951 <p>Use this parameter to change the types of block braces for which the <b>-bli</b> flag applies; see <a href="#Specifying-Block-Types">&quot;Specifying Block Types&quot;</a>.</p>
1952
1953 <p>The default is <b>-blil=&#39;if else elsif unless while for foreach do : sub&#39;</b>.</p>
1954
1955 </dd>
1956 <dt id="blixl-s---brace-left-and-indent-exclusion-list-s"><b>-blixl=s</b>, <b>--brace-left-and-indent-exclusion-list=s</b></dt>
1957 <dd>
1958
1959 <p>Use this parameter to exclude types of block braces for which the <b>-bli</b> flag applies; see <a href="#Specifying-Block-Types">&quot;Specifying Block Types&quot;</a>.</p>
1960
1961 <p>This might be useful in conjunction with selecting all blocks <b>-blil=&#39;*&#39;</b>. The default setting is <b>-blixl=&#39; &#39;</b>, which does not exclude any blocks.</p>
1962
1963 <p>Note that the two parameters <b>-blil</b> and <b>-blixl</b> control the behavior of the <b>-bli</b> flag but have no effect unless the <b>-bli</b> flag is set.</p>
1964
1965 </dd>
1966 <dt id="bar---opening-brace-always-on-right"><b>-bar</b>, <b>--opening-brace-always-on-right</b></dt>
1967 <dd>
1968
1969 <p>The default style, <b>-nbl</b> places the opening code block brace on a new line if it does not fit on the same line as the opening keyword, like this:</p>
1970
1971 <pre><code>        if ( $bigwasteofspace1 &amp;&amp; $bigwasteofspace2
1972           || $bigwasteofspace3 &amp;&amp; $bigwasteofspace4 )
1973         {
1974             big_waste_of_time();
1975         }</code></pre>
1976
1977 <p>To force the opening brace to always be on the right, use the <b>-bar</b> flag. In this case, the above example becomes</p>
1978
1979 <pre><code>        if ( $bigwasteofspace1 &amp;&amp; $bigwasteofspace2
1980           || $bigwasteofspace3 &amp;&amp; $bigwasteofspace4 ) {
1981             big_waste_of_time();
1982         }</code></pre>
1983
1984 <p>A conflict occurs if both <b>-bl</b> and <b>-bar</b> are specified.</p>
1985
1986 </dd>
1987 <dt id="otr---opening-token-right-and-related-flags"><b>-otr</b>, <b>--opening-token-right</b> and related flags</dt>
1988 <dd>
1989
1990 <p>The <b>-otr</b> flag is a hint that perltidy should not place a break between a comma and an opening token. For example:</p>
1991
1992 <pre><code>    # default formatting
1993     push @{ $self-&gt;{$module}{$key} },
1994       {
1995         accno       =&gt; $ref-&gt;{accno},
1996         description =&gt; $ref-&gt;{description}
1997       };
1998
1999     # perltidy -otr
2000     push @{ $self-&gt;{$module}{$key} }, {
2001         accno       =&gt; $ref-&gt;{accno},
2002         description =&gt; $ref-&gt;{description}
2003       };</code></pre>
2004
2005 <p>The flag <b>-otr</b> is actually an abbreviation for three other flags which can be used to control parens, hash braces, and square brackets separately if desired:</p>
2006
2007 <pre><code>  -opr  or --opening-paren-right
2008   -ohbr or --opening-hash-brace-right
2009   -osbr or --opening-square-bracket-right</code></pre>
2010
2011 </dd>
2012 <dt id="bbhb-n---break-before-hash-brace-n-and-related-flags"><b>-bbhb=n</b>, <b>--break-before-hash-brace=n</b> and related flags</dt>
2013 <dd>
2014
2015 <p>When a list of items spans multiple lines, the default formatting is to place the opening brace (or other container token) at the end of the starting line, like this:</p>
2016
2017 <pre><code>    $romanNumerals = {
2018         one   =&gt; &#39;I&#39;,
2019         two   =&gt; &#39;II&#39;,
2020         three =&gt; &#39;III&#39;,
2021         four  =&gt; &#39;IV&#39;,
2022     };</code></pre>
2023
2024 <p>This flag can change the default behavior to cause a line break to be placed before the opening brace according to the value given to the integer <b>n</b>:</p>
2025
2026 <pre><code>  -bbhb=0 never break [default]
2027   -bbhb=1 stable: break if the input script had a break
2028   -bbhb=2 break if list is &#39;complex&#39; (see note below)
2029   -bbhb=3 always break</code></pre>
2030
2031 <p>For example,</p>
2032
2033 <pre><code>    # perltidy -bbhb=3
2034     $romanNumerals =
2035       {
2036         one   =&gt; &#39;I&#39;,
2037         two   =&gt; &#39;II&#39;,
2038         three =&gt; &#39;III&#39;,
2039         four  =&gt; &#39;IV&#39;,
2040       };</code></pre>
2041
2042 <p>There are several points to note about this flag:</p>
2043
2044 <ul>
2045
2046 <li><p>This parameter only applies if the opening brace is preceded by an &#39;=&#39; or &#39;=&gt;&#39;.</p>
2047
2048 </li>
2049 <li><p>This parameter only applies if the contents of the container looks like a list. The contents need to contain some commas or &#39;=&gt;&#39;s at the next interior level to be considered a list.</p>
2050
2051 </li>
2052 <li><p>For the <b>n=2</b> option, a list is considered &#39;complex&#39; if it is part of a nested list structure which spans multiple lines in the input file.</p>
2053
2054 </li>
2055 <li><p>If multiple opening tokens have been &#39;welded&#39; together with the <b>-wn</b> parameter, then this parameter has no effect.</p>
2056
2057 </li>
2058 <li><p>The indentation of the braces will normally be one level of continuation indentation by default. This can be changed with the parameter <b>-bbhbi=n</b> in the next section.</p>
2059
2060 </li>
2061 <li><p>Similar flags for controlling parens and square brackets are given in the subsequent section.</p>
2062
2063 </li>
2064 </ul>
2065
2066 </dd>
2067 <dt id="bbhbi-n---break-before-hash-brace-and-indent-n"><b>-bbhbi=n</b>, <b>--break-before-hash-brace-and-indent=n</b></dt>
2068 <dd>
2069
2070 <p>This flag is a companion to <b>-bbhb=n</b> for controlling the indentation of an opening hash brace which is placed on a new line by that parameter. The indentation is as follows:</p>
2071
2072 <pre><code>  -bbhbi=0 one continuation level [default]
2073   -bbhbi=1 outdent by one continuation level
2074   -bbhbi=2 indent one full indentation level</code></pre>
2075
2076 <p>For example:</p>
2077
2078 <pre><code>    # perltidy -bbhb=3 -bbhbi=1
2079     $romanNumerals =
2080     {
2081         one   =&gt; &#39;I&#39;,
2082         two   =&gt; &#39;II&#39;,
2083         three =&gt; &#39;III&#39;,
2084         four  =&gt; &#39;IV&#39;,
2085     };
2086
2087     # perltidy -bbhb=3 -bbhbi=2
2088     $romanNumerals =
2089         {
2090         one   =&gt; &#39;I&#39;,
2091         two   =&gt; &#39;II&#39;,
2092         three =&gt; &#39;III&#39;,
2093         four  =&gt; &#39;IV&#39;,
2094         };</code></pre>
2095
2096 <p>Note that this parameter has no effect unless <b>-bbhb=n</b> is also set.</p>
2097
2098 </dd>
2099 <dt id="bbsb-n---break-before-square-bracket-n"><b>-bbsb=n</b>, <b>--break-before-square-bracket=n</b></dt>
2100 <dd>
2101
2102 <p>This flag is similar to the flag described above, except it applies to lists contained within square brackets.</p>
2103
2104 <pre><code>  -bbsb=0 never break [default]
2105   -bbsb=1 stable: break if the input script had a break
2106   -bbsb=2 break if list is &#39;complex&#39; (part of nested list structure)
2107   -bbsb=3 always break</code></pre>
2108
2109 </dd>
2110 <dt id="bbsbi-n---break-before-square-bracket-and-indent-n"><b>-bbsbi=n</b>, <b>--break-before-square-bracket-and-indent=n</b></dt>
2111 <dd>
2112
2113 <p>This flag is a companion to <b>-bbsb=n</b> for controlling the indentation of an opening square bracket which is placed on a new line by that parameter. The indentation is as follows:</p>
2114
2115 <pre><code>  -bbsbi=0 one continuation level [default]
2116   -bbsbi=1 outdent by one continuation level
2117   -bbsbi=2 indent one full indentation level</code></pre>
2118
2119 </dd>
2120 <dt id="bbp-n---break-before-paren-n"><b>-bbp=n</b>, <b>--break-before-paren=n</b></dt>
2121 <dd>
2122
2123 <p>This flag is similar to <b>-bbhb=n</b>, described above, except it applies to lists contained within parens.</p>
2124
2125 <pre><code>  -bbp=0 never break [default]
2126   -bbp=1 stable: break if the input script had a break
2127   -bpb=2 break if list is &#39;complex&#39; (part of nested list structure)
2128   -bbp=3 always break</code></pre>
2129
2130 </dd>
2131 <dt id="bbpi-n---break-before-paren-and-indent-n"><b>-bbpi=n</b>, <b>--break-before-paren-and-indent=n</b></dt>
2132 <dd>
2133
2134 <p>This flag is a companion to <b>-bbp=n</b> for controlling the indentation of an opening paren which is placed on a new line by that parameter. The indentation is as follows:</p>
2135
2136 <pre><code>  -bbpi=0 one continuation level [default]
2137   -bbpi=1 outdent by one continuation level
2138   -bbpi=2 indent one full indentation level</code></pre>
2139
2140 </dd>
2141 <dt id="wn---weld-nested-containers"><b>-wn</b>, <b>--weld-nested-containers</b></dt>
2142 <dd>
2143
2144 <p>The <b>-wn</b> flag causes closely nested pairs of opening and closing container symbols (curly braces, brackets, or parens) to be &quot;welded&quot; together, meaning that they are treated as if combined into a single unit, with the indentation of the innermost code reduced to be as if there were just a single container symbol.</p>
2145
2146 <p>For example:</p>
2147
2148 <pre><code>        # default formatting
2149         do {
2150             {
2151                 next if $x == $y;
2152             }
2153         } until $x++ &gt; $z;
2154
2155         # perltidy -wn
2156         do { {
2157             next if $x == $y;
2158         } } until $x++ &gt; $z;</code></pre>
2159
2160 <p>When this flag is set perltidy makes a preliminary pass through the file and identifies all nested pairs of containers. To qualify as a nested pair, the closing container symbols must be immediately adjacent and the opening symbols must either (1) be adjacent as in the above example, or (2) have an anonymous sub declaration following an outer opening container symbol which is not a code block brace, or (3) have an outer opening paren separated from the inner opening symbol by any single non-container symbol or something that looks like a function evaluation, as illustrated in the next examples.</p>
2161
2162 <p>Any container symbol may serve as both the inner container of one pair and as the outer container of an adjacent pair. Consequently, any number of adjacent opening or closing symbols may join together in weld. For example, here are three levels of wrapped function calls:</p>
2163
2164 <pre><code>        # default formatting
2165         my (@date_time) = Localtime(
2166             Date_to_Time(
2167                 Add_Delta_DHMS(
2168                     $year, $month,  $day, $hour, $minute, $second,
2169                     &#39;0&#39;,   $offset, &#39;0&#39;,  &#39;0&#39;
2170                 )
2171             )
2172         );
2173
2174         # perltidy -wn
2175         my (@date_time) = Localtime( Date_to_Time( Add_Delta_DHMS(
2176             $year, $month,  $day, $hour, $minute, $second,
2177             &#39;0&#39;,   $offset, &#39;0&#39;,  &#39;0&#39;
2178         ) ) );</code></pre>
2179
2180 <p>Notice how the indentation of the inner lines are reduced by two levels in this case. This example also shows the typical result of this formatting, namely it is a sandwich consisting of an initial opening layer, a central section of any complexity forming the &quot;meat&quot; of the sandwich, and a final closing layer. This predictable structure helps keep the compacted structure readable.</p>
2181
2182 <p>The inner sandwich layer is required to be at least one line thick. If this cannot be achieved, welding does not occur. This constraint can cause formatting to take a couple of iterations to stabilize when it is first applied to a script. The <b>-conv</b> flag can be used to insure that the final format is achieved in a single run.</p>
2183
2184 <p>Here is an example illustrating a welded container within a welded containers:</p>
2185
2186 <pre><code>        # default formatting
2187         $x-&gt;badd(
2188             bmul(
2189                 $class-&gt;new(
2190                     abs(
2191                         $sx * int( $xr-&gt;numify() ) &amp; $sy * int( $yr-&gt;numify() )
2192                     )
2193                 ),
2194                 $m
2195             )
2196         );
2197
2198         # perltidy -wn
2199         $x-&gt;badd( bmul(
2200             $class-&gt;new( abs(
2201                 $sx * int( $xr-&gt;numify() ) &amp; $sy * int( $yr-&gt;numify() )
2202             ) ),
2203             $m
2204         ) );</code></pre>
2205
2206 <p>The welded closing tokens are by default on a separate line but this can be modified with the <b>-vtc=n</b> flag (described in the next section). For example, the same example adding <b>-vtc=2</b> is</p>
2207
2208 <pre><code>        # perltidy -wn -vtc=2
2209         $x-&gt;badd( bmul(
2210             $class-&gt;new( abs(
2211                 $sx * int( $xr-&gt;numify() ) &amp; $sy * int( $yr-&gt;numify() ) ) ),
2212             $m ) );</code></pre>
2213
2214 <p>This format option is quite general but there are some limitations.</p>
2215
2216 <p>One limitation is that any line length limit still applies and can cause long welded sections to be broken into multiple lines.</p>
2217
2218 <p>Another limitation is that an opening symbol which delimits quoted text cannot be included in a welded pair. This is because quote delimiters are treated specially in perltidy.</p>
2219
2220 <p>Finally, the stacking of containers defined by this flag have priority over any other container stacking flags. This is because any welding is done first.</p>
2221
2222 </dd>
2223 <dt id="wnxl-s---weld-nested-exclusion-list"><b>-wnxl=s</b>, <b>--weld-nested-exclusion-list</b></dt>
2224 <dd>
2225
2226 <p>The <b>-wnxl=s</b> flag provides some control over the types of containers which can be welded. The <b>-wn</b> flag by default is &quot;greedy&quot; in welding adjacent containers. If it welds more types of containers than desired, this flag provides a capability to reduce the amount of welding by specifying a list of things which should <b>not</b> be welded.</p>
2227
2228 <p>The logic in perltidy to apply this is straightforward. As each container token is being considered for joining a weld, any exclusion rules are consulted and used to reject the weld if necessary.</p>
2229
2230 <p>This list is a string with space-separated items. Each item consists of up to three pieces of information: (1) an optional position, (2) an optional preceding type, and (3) a container type.</p>
2231
2232 <p>The only required piece of information is a container type, which is one of &#39;(&#39;, &#39;[&#39;, &#39;{&#39; or &#39;q&#39;. The first three of these are container tokens and the last represents a quoted list. For example the string</p>
2233
2234 <pre><code>  -wnxl=&#39;[ { q&#39;</code></pre>
2235
2236 <p>means do <b>NOT</b> include square-bracets, braces, or quotes in any welds. The only unspecified container is &#39;(&#39;, so this string means that only welds involving parens will be made.</p>
2237
2238 <p>To illustrate, following welded snippet consists of a chain of three welded containers with types &#39;(&#39; &#39;[&#39; and &#39;q&#39;:</p>
2239
2240 <pre><code>    # perltidy -wn
2241     skip_symbols( [ qw(
2242         Perl_dump_fds
2243         Perl_ErrorNo
2244         Perl_GetVars
2245         PL_sys_intern
2246     ) ] );</code></pre>
2247
2248 <p>Even though the qw term uses parens as the quote delimiter, it has a special type &#39;q&#39; here. If it appears in a weld it always appears at the end of the welded chain.</p>
2249
2250 <p>Any of the container types &#39;[&#39;, &#39;{&#39;, and &#39;(&#39; may be prefixed with a position indicator which is either &#39;^&#39;, to indicate the first token of a welded sequence, or &#39;.&#39;, to indicate an interior token of a welded sequence. (Since a quoted string &#39;q&#39; always ends a chain it does need a position indicator).</p>
2251
2252 <p>For example, if we do not want a sequence of welded containers to start with a square bracket we could use</p>
2253
2254 <pre><code>  -wnxl=&#39;^[&#39;</code></pre>
2255
2256 <p>In the above snippet, there is a square bracket but it does not start the chain, so the formatting would be unchanged if it were formatted with this restriction.</p>
2257
2258 <p>A third optional item of information which can be given is an alphanumeric letter which is used to limit the selection further depending on the type of token immediately before the container. If given, it goes just before the container symbol. The possible letters are currently &#39;k&#39;, &#39;K&#39;, &#39;f&#39;, &#39;F&#39;, &#39;w&#39;, and &#39;W&#39;, with these meanings:</p>
2259
2260 <pre><code> &#39;k&#39; matches if the previous nonblank token is a perl builtin keyword (such as &#39;if&#39;, &#39;while&#39;),
2261  &#39;K&#39; matches if &#39;k&#39; does not, meaning that the previous token is not a keyword.
2262  &#39;f&#39; matches if the previous token is a function other than a keyword.
2263  &#39;F&#39; matches if &#39;f&#39; does not.
2264  &#39;w&#39; matches if either &#39;k&#39; or &#39;f&#39; match.
2265  &#39;W&#39; matches if &#39;w&#39; does not.</code></pre>
2266
2267 <p>For example, compare</p>
2268
2269 <pre><code>        # perltidy -wn
2270         if ( defined( $_Cgi_Query{
2271             $Config{&#39;methods&#39;}{&#39;authentication&#39;}{&#39;remote&#39;}{&#39;cgi&#39;}{&#39;username&#39;}
2272         } ) )</code></pre>
2273
2274 <p>with</p>
2275
2276 <pre><code>        # perltidy -wn -wnxl=&#39;^K( {&#39;
2277         if ( defined(
2278             $_Cgi_Query{ $Config{&#39;methods&#39;}{&#39;authentication&#39;}{&#39;remote&#39;}{&#39;cgi&#39;}
2279                   {&#39;username&#39;} }
2280         ) )</code></pre>
2281
2282 <p>The first case does maximum welding. In the second case the leading paren is retained by the rule (it would have been rejected if preceded by a non-keyword) but the curly brace is rejected by the rule.</p>
2283
2284 <p>Here are some additional example strings and their meanings:</p>
2285
2286 <pre><code>    &#39;^(&#39;   - the weld must not start with a paren
2287     &#39;.(&#39;   - the second and later tokens may not be parens
2288     &#39;.w(&#39;  - the second and later tokens may not keyword or function call parens
2289     &#39;(&#39;    - no parens in a weld
2290     &#39;^K(&#39;  - exclude a leading paren preceded by a non-keyword
2291     &#39;.k(&#39;  - exclude a secondary paren preceded by a keyword
2292     &#39;[ {&#39;  - exclude all brackets and braces
2293     &#39;[ ( ^K{&#39; - exclude everything except nested structures like do {{  ... }}</code></pre>
2294
2295 </dd>
2296 <dt id="Vertical-tightness-of-non-block-curly-braces-parentheses-and-square-brackets"><b>Vertical tightness</b> of non-block curly braces, parentheses, and square brackets.</dt>
2297 <dd>
2298
2299 <p>These parameters control what shall be called vertical tightness. Here are the main points:</p>
2300
2301 <ul>
2302
2303 <li><p>Opening tokens (except for block braces) are controlled by <b>-vt=n</b>, or <b>--vertical-tightness=n</b>, where</p>
2304
2305 <pre><code> -vt=0 always break a line after opening token (default).
2306  -vt=1 do not break unless this would produce more than one
2307          step in indentation in a line.
2308  -vt=2 never break a line after opening token</code></pre>
2309
2310 </li>
2311 <li><p>You must also use the <b>-lp</b> flag when you use the <b>-vt</b> flag; the reason is explained below.</p>
2312
2313 </li>
2314 <li><p>Closing tokens (except for block braces) are controlled by <b>-vtc=n</b>, or <b>--vertical-tightness-closing=n</b>, where</p>
2315
2316 <pre><code> -vtc=0 always break a line before a closing token (default),
2317  -vtc=1 do not break before a closing token which is followed
2318         by a semicolon or another closing token, and is not in
2319         a list environment.
2320  -vtc=2 never break before a closing token.
2321  -vtc=3 Like -vtc=1 except always break before a closing token
2322         if the corresponding opening token follows an = or =&gt;.</code></pre>
2323
2324 <p>The rules for <b>-vtc=1</b> and <b>-vtc=3</b> are designed to maintain a reasonable balance between tightness and readability in complex lists.</p>
2325
2326 </li>
2327 <li><p>Different controls may be applied to different token types, and it is also possible to control block braces; see below.</p>
2328
2329 </li>
2330 <li><p>Finally, please note that these vertical tightness flags are merely hints to the formatter, and it cannot always follow them. Things which make it difficult or impossible include comments, blank lines, blocks of code within a list, and possibly the lack of the <b>-lp</b> parameter. Also, these flags may be ignored for very small lists (2 or 3 lines in length).</p>
2331
2332 </li>
2333 </ul>
2334
2335 <p>Here are some examples:</p>
2336
2337 <pre><code>    # perltidy -lp -vt=0 -vtc=0
2338     %romanNumerals = (
2339                        one   =&gt; &#39;I&#39;,
2340                        two   =&gt; &#39;II&#39;,
2341                        three =&gt; &#39;III&#39;,
2342                        four  =&gt; &#39;IV&#39;,
2343     );
2344
2345     # perltidy -lp -vt=1 -vtc=0
2346     %romanNumerals = ( one   =&gt; &#39;I&#39;,
2347                        two   =&gt; &#39;II&#39;,
2348                        three =&gt; &#39;III&#39;,
2349                        four  =&gt; &#39;IV&#39;,
2350     );
2351
2352     # perltidy -lp -vt=1 -vtc=1
2353     %romanNumerals = ( one   =&gt; &#39;I&#39;,
2354                        two   =&gt; &#39;II&#39;,
2355                        three =&gt; &#39;III&#39;,
2356                        four  =&gt; &#39;IV&#39;, );
2357
2358     # perltidy -vtc=3
2359     my_function(
2360         one   =&gt; &#39;I&#39;,
2361         two   =&gt; &#39;II&#39;,
2362         three =&gt; &#39;III&#39;,
2363         four  =&gt; &#39;IV&#39;, );
2364
2365     # perltidy -vtc=3
2366     %romanNumerals = (
2367         one   =&gt; &#39;I&#39;,
2368         two   =&gt; &#39;II&#39;,
2369         three =&gt; &#39;III&#39;,
2370         four  =&gt; &#39;IV&#39;,
2371     );</code></pre>
2372
2373 <p>In the last example for <b>-vtc=3</b>, the opening paren is preceded by an equals so the closing paren is placed on a new line.</p>
2374
2375 <p>The difference between <b>-vt=1</b> and <b>-vt=2</b> is shown here:</p>
2376
2377 <pre><code>    # perltidy -lp -vt=1
2378     $init-&gt;add(
2379                 mysprintf( &quot;(void)find_threadsv(%s);&quot;,
2380                            cstring( $threadsv_names[ $op-&gt;targ ] )
2381                 )
2382     );
2383
2384     # perltidy -lp -vt=2
2385     $init-&gt;add( mysprintf( &quot;(void)find_threadsv(%s);&quot;,
2386                            cstring( $threadsv_names[ $op-&gt;targ ] )
2387                 )
2388     );</code></pre>
2389
2390 <p>With <b>-vt=1</b>, the line ending in <code>add(</code> does not combine with the next line because the next line is not balanced. This can help with readability, but <b>-vt=2</b> can be used to ignore this rule.</p>
2391
2392 <p>The tightest, and least readable, code is produced with both <code>-vt=2</code> and <code>-vtc=2</code>:</p>
2393
2394 <pre><code>    # perltidy -lp -vt=2 -vtc=2
2395     $init-&gt;add( mysprintf( &quot;(void)find_threadsv(%s);&quot;,
2396                            cstring( $threadsv_names[ $op-&gt;targ ] ) ) );</code></pre>
2397
2398 <p>Notice how the code in all of these examples collapses vertically as <b>-vt</b> increases, but the indentation remains unchanged. This is because perltidy implements the <b>-vt</b> parameter by first formatting as if <b>-vt=0</b>, and then simply overwriting one output line on top of the next, if possible, to achieve the desired vertical tightness. The <b>-lp</b> indentation style has been designed to allow this vertical collapse to occur, which is why it is required for the <b>-vt</b> parameter.</p>
2399
2400 <p>The <b>-vt=n</b> and <b>-vtc=n</b> parameters apply to each type of container token. If desired, vertical tightness controls can be applied independently to each of the closing container token types.</p>
2401
2402 <p>The parameters for controlling parentheses are <b>-pvt=n</b> or <b>--paren-vertical-tightness=n</b>, and <b>-pvtc=n</b> or <b>--paren-vertical-tightness-closing=n</b>.</p>
2403
2404 <p>Likewise, the parameters for square brackets are <b>-sbvt=n</b> or <b>--square-bracket-vertical-tightness=n</b>, and <b>-sbvtc=n</b> or <b>--square-bracket-vertical-tightness-closing=n</b>.</p>
2405
2406 <p>Finally, the parameters for controlling non-code block braces are <b>-bvt=n</b> or <b>--brace-vertical-tightness=n</b>, and <b>-bvtc=n</b> or <b>--brace-vertical-tightness-closing=n</b>.</p>
2407
2408 <p>In fact, the parameter <b>-vt=n</b> is actually just an abbreviation for <b>-pvt=n -bvt=n sbvt=n</b>, and likewise <b>-vtc=n</b> is an abbreviation for <b>-pvtc=n -bvtc=n -sbvtc=n</b>.</p>
2409
2410 </dd>
2411 <dt id="bbvt-n-or---block-brace-vertical-tightness-n"><b>-bbvt=n</b> or <b>--block-brace-vertical-tightness=n</b></dt>
2412 <dd>
2413
2414 <p>The <b>-bbvt=n</b> flag is just like the <b>-vt=n</b> flag but applies to opening code block braces.</p>
2415
2416 <pre><code> -bbvt=0 break after opening block brace (default).
2417  -bbvt=1 do not break unless this would produce more than one
2418          step in indentation in a line.
2419  -bbvt=2 do not break after opening block brace.</code></pre>
2420
2421 <p>It is necessary to also use either <b>-bl</b> or <b>-bli</b> for this to work, because, as with other vertical tightness controls, it is implemented by simply overwriting a line ending with an opening block brace with the subsequent line. For example:</p>
2422
2423 <pre><code>    # perltidy -bli -bbvt=0
2424     if ( open( FILE, &quot;&lt; $File&quot; ) )
2425       {
2426         while ( $File = &lt;FILE&gt; )
2427           {
2428             $In .= $File;
2429             $count++;
2430           }
2431         close(FILE);
2432       }
2433
2434     # perltidy -bli -bbvt=1
2435     if ( open( FILE, &quot;&lt; $File&quot; ) )
2436       { while ( $File = &lt;FILE&gt; )
2437           { $In .= $File;
2438             $count++;
2439           }
2440         close(FILE);
2441       }</code></pre>
2442
2443 <p>By default this applies to blocks associated with keywords <b>if</b>, <b>elsif</b>, <b>else</b>, <b>unless</b>, <b>for</b>, <b>foreach</b>, <b>sub</b>, <b>while</b>, <b>until</b>, and also with a preceding label. This can be changed with the parameter <b>-bbvtl=string</b>, or <b>--block-brace-vertical-tightness-list=string</b>, where <b>string</b> is a space-separated list of block types. For more information on the possible values of this string, see <a href="#Specifying-Block-Types">&quot;Specifying Block Types&quot;</a></p>
2444
2445 <p>For example, if we want to just apply this style to <code>if</code>, <code>elsif</code>, and <code>else</code> blocks, we could use <code>perltidy -bli -bbvt=1 -bbvtl=&#39;if elsif else&#39;</code>.</p>
2446
2447 <p>There is no vertical tightness control for closing block braces; with one exception they will be placed on separate lines. The exception is that a cascade of closing block braces may be stacked on a single line. See <b>-scbb</b>.</p>
2448
2449 </dd>
2450 <dt id="sot---stack-opening-tokens-and-related-flags"><b>-sot</b>, <b>--stack-opening-tokens</b> and related flags</dt>
2451 <dd>
2452
2453 <p>The <b>-sot</b> flag tells perltidy to &quot;stack&quot; opening tokens when possible to avoid lines with isolated opening tokens.</p>
2454
2455 <p>For example:</p>
2456
2457 <pre><code>    # default
2458     $opt_c = Text::CSV_XS-&gt;new(
2459         {
2460             binary       =&gt; 1,
2461             sep_char     =&gt; $opt_c,
2462             always_quote =&gt; 1,
2463         }
2464     );
2465
2466     # -sot
2467     $opt_c = Text::CSV_XS-&gt;new( {
2468             binary       =&gt; 1,
2469             sep_char     =&gt; $opt_c,
2470             always_quote =&gt; 1,
2471         }
2472     );</code></pre>
2473
2474 <p>For detailed control of individual closing tokens the following controls can be used:</p>
2475
2476 <pre><code>  -sop  or --stack-opening-paren
2477   -sohb or --stack-opening-hash-brace
2478   -sosb or --stack-opening-square-bracket
2479   -sobb or --stack-opening-block-brace</code></pre>
2480
2481 <p>The flag <b>-sot</b> is an abbreviation for <b>-sop -sohb -sosb</b>.</p>
2482
2483 <p>The flag <b>-sobb</b> is an abbreviation for <b>-bbvt=2 -bbvtl=&#39;*&#39;</b>. This will case a cascade of opening block braces to appear on a single line, although this an uncommon occurrence except in test scripts.</p>
2484
2485 </dd>
2486 <dt id="sct---stack-closing-tokens-and-related-flags"><b>-sct</b>, <b>--stack-closing-tokens</b> and related flags</dt>
2487 <dd>
2488
2489 <p>The <b>-sct</b> flag tells perltidy to &quot;stack&quot; closing tokens when possible to avoid lines with isolated closing tokens.</p>
2490
2491 <p>For example:</p>
2492
2493 <pre><code>    # default
2494     $opt_c = Text::CSV_XS-&gt;new(
2495         {
2496             binary       =&gt; 1,
2497             sep_char     =&gt; $opt_c,
2498             always_quote =&gt; 1,
2499         }
2500     );
2501
2502     # -sct
2503     $opt_c = Text::CSV_XS-&gt;new(
2504         {
2505             binary       =&gt; 1,
2506             sep_char     =&gt; $opt_c,
2507             always_quote =&gt; 1,
2508         } );</code></pre>
2509
2510 <p>The <b>-sct</b> flag is somewhat similar to the <b>-vtc</b> flags, and in some cases it can give a similar result. The difference is that the <b>-vtc</b> flags try to avoid lines with leading opening tokens by &quot;hiding&quot; them at the end of a previous line, whereas the <b>-sct</b> flag merely tries to reduce the number of lines with isolated closing tokens by stacking them but does not try to hide them. For example:</p>
2511
2512 <pre><code>    # -vtc=2
2513     $opt_c = Text::CSV_XS-&gt;new(
2514         {
2515             binary       =&gt; 1,
2516             sep_char     =&gt; $opt_c,
2517             always_quote =&gt; 1, } );</code></pre>
2518
2519 <p>For detailed control of the stacking of individual closing tokens the following controls can be used:</p>
2520
2521 <pre><code>  -scp  or --stack-closing-paren
2522   -schb or --stack-closing-hash-brace
2523   -scsb or --stack-closing-square-bracket
2524   -scbb or --stack-closing-block-brace</code></pre>
2525
2526 <p>The flag <b>-sct</b> is an abbreviation for stacking the non-block closing tokens, <b>-scp -schb -scsb</b>.</p>
2527
2528 <p>Stacking of closing block braces, <b>-scbb</b>, causes a cascade of isolated closing block braces to be combined into a single line as in the following example:</p>
2529
2530 <pre><code>    # -scbb:
2531     for $w1 (@w1) {
2532         for $w2 (@w2) {
2533             for $w3 (@w3) {
2534                 for $w4 (@w4) {
2535                     push( @lines, &quot;$w1 $w2 $w3 $w4\n&quot; );
2536                 } } } }</code></pre>
2537
2538 <p>To simplify input even further for the case in which both opening and closing non-block containers are stacked, the flag <b>-sac</b> or <b>--stack-all-containers</b> is an abbreviation for <b>-sot -sct</b>.</p>
2539
2540 <p>Please note that if both opening and closing tokens are to be stacked, then the newer flag <b>-weld-nested-containers</b> may be preferable because it insures that stacking is always done symmetrically. It also removes an extra level of unnecessary indentation within welded containers. It is able to do this because it works on formatting globally rather than locally, as the <b>-sot</b> and <b>-sct</b> flags do.</p>
2541
2542 </dd>
2543 <dt id="dnl---delete-old-newlines"><b>-dnl</b>, <b>--delete-old-newlines</b></dt>
2544 <dd>
2545
2546 <p>By default, perltidy first deletes all old line break locations, and then it looks for good break points to match the desired line length. Use <b>-ndnl</b> or <b>--nodelete-old-newlines</b> to force perltidy to retain all old line break points.</p>
2547
2548 </dd>
2549 <dt id="anl---add-newlines"><b>-anl</b>, <b>--add-newlines</b></dt>
2550 <dd>
2551
2552 <p>By default, perltidy will add line breaks when necessary to create continuations of long lines and to improve the script appearance. Use <b>-nanl</b> or <b>--noadd-newlines</b> to prevent any new line breaks.</p>
2553
2554 <p>This flag does not prevent perltidy from eliminating existing line breaks; see <b>--freeze-newlines</b> to completely prevent changes to line break points.</p>
2555
2556 </dd>
2557 <dt id="Controlling-whether-perltidy-breaks-before-or-after-operators"><b>Controlling whether perltidy breaks before or after operators</b></dt>
2558 <dd>
2559
2560 <p>Four command line parameters provide some control over whether a line break should be before or after specific token types. Two parameters give detailed control:</p>
2561
2562 <p><b>-wba=s</b> or <b>--want-break-after=s</b>, and</p>
2563
2564 <p><b>-wbb=s</b> or <b>--want-break-before=s</b>.</p>
2565
2566 <p>These parameters are each followed by a quoted string, <b>s</b>, containing a list of token types (separated only by spaces). No more than one of each of these parameters should be specified, because repeating a command-line parameter always overwrites the previous one before perltidy ever sees it.</p>
2567
2568 <p>By default, perltidy breaks <b>after</b> these token types: % + - * / x != == &gt;= &lt;= =~ !~ &lt; &gt; | &amp; = **= += *= &amp;= &lt;&lt;= &amp;&amp;= -= /= |= &gt;&gt;= ||= //= .= %= ^= x=</p>
2569
2570 <p>And perltidy breaks <b>before</b> these token types by default: . &lt;&lt; &gt;&gt; -&gt; &amp;&amp; || //</p>
2571
2572 <p>To illustrate, to cause a break after a concatenation operator, <code>&#39;.&#39;</code>, rather than before it, the command line would be</p>
2573
2574 <pre><code>  -wba=&quot;.&quot;</code></pre>
2575
2576 <p>As another example, the following command would cause a break before math operators <code>&#39;+&#39;</code>, <code>&#39;-&#39;</code>, <code>&#39;/&#39;</code>, and <code>&#39;*&#39;</code>:</p>
2577
2578 <pre><code>  -wbb=&quot;+ - / *&quot;</code></pre>
2579
2580 <p>These commands should work well for most of the token types that perltidy uses (use <b>--dump-token-types</b> for a list). Also try the <b>-D</b> flag on a short snippet of code and look at the .DEBUG file to see the tokenization. However, for a few token types there may be conflicts with hardwired logic which cause unexpected results. One example is curly braces, which should be controlled with the parameter <b>bl</b> provided for that purpose.</p>
2581
2582 <p><b>WARNING</b> Be sure to put these tokens in quotes to avoid having them misinterpreted by your command shell.</p>
2583
2584 <p>Two additional parameters are available which, though they provide no further capability, can simplify input are:</p>
2585
2586 <p><b>-baao</b> or <b>--break-after-all-operators</b>,</p>
2587
2588 <p><b>-bbao</b> or <b>--break-before-all-operators</b>.</p>
2589
2590 <p>The -baao sets the default to be to break after all of the following operators:</p>
2591
2592 <pre><code>    % + - * / x != == &gt;= &lt;= =~ !~ &lt; &gt; | &amp;
2593     = **= += *= &amp;= &lt;&lt;= &amp;&amp;= -= /= |= &gt;&gt;= ||= //= .= %= ^= x=
2594     . : ? &amp;&amp; || and or err xor</code></pre>
2595
2596 <p>and the <b>-bbao</b> flag sets the default to break before all of these operators. These can be used to define an initial break preference which can be fine-tuned with the <b>-wba</b> and <b>-wbb</b> flags. For example, to break before all operators except an <b>=</b> one could use --bbao -wba=&#39;=&#39; rather than listing every single perl operator except <b>=</b> on a -wbb flag.</p>
2597
2598 </dd>
2599 <dt id="bal-n---break-after-labels-n"><b>bal=n, --break-after-labels=n</b></dt>
2600 <dd>
2601
2602 <p>This flag controls whether or not a line break occurs after a label. There are three possible valuse for <b>n</b>:</p>
2603
2604 <pre><code>  -bal=0  break if there is a break in the input [DEFAULt]
2605   -bal=1  always break after a label
2606   -bal=2  never break after a label</code></pre>
2607
2608 <p>For example,</p>
2609
2610 <pre><code>      # perltidy -bal=1
2611       RETURN:
2612         return;
2613
2614       # perltidy -bal=2
2615       RETURN: return;</code></pre>
2616
2617 </dd>
2618 </dl>
2619
2620 <h2 id="Controlling-List-Formatting">Controlling List Formatting</h2>
2621
2622 <p>Perltidy attempts to format lists of comma-separated values in tables which look good. Its default algorithms usually work well, but sometimes they don&#39;t. In this case, there are several methods available to control list formatting.</p>
2623
2624 <p>A very simple way to prevent perltidy from changing the line breaks within a comma-separated list of values is to insert a blank line, comment, or side-comment anywhere between the opening and closing parens (or braces or brackets). This causes perltidy to skip over its list formatting logic. (The reason is that any of these items put a constraint on line breaks, and perltidy needs complete control over line breaks within a container to adjust a list layout). For example, let us consider</p>
2625
2626 <pre><code>    my @list = (1,
2627                 1, 1,
2628                 1, 2, 1,
2629                 1, 3, 3, 1,
2630                 1, 4, 6, 4, 1,);</code></pre>
2631
2632 <p>The default formatting, which allows a maximum line length of 80, will flatten this down to one line:</p>
2633
2634 <pre><code>    # perltidy (default)
2635     my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );</code></pre>
2636
2637 <p>This formatting loses the nice structure. If we place a side comment anywhere between the opening and closing parens, the original line break points are retained. For example,</p>
2638
2639 <pre><code>    my @list = (
2640         1,    # a side comment forces the original line breakpoints to be kept
2641         1, 1,
2642         1, 2, 1,
2643         1, 3, 3, 1,
2644         1, 4, 6, 4, 1,
2645     );</code></pre>
2646
2647 <p>The side comment can be a single hash symbol without any text. We could achieve the same result with a blank line or full comment anywhere between the opening and closing parens. Vertical alignment of the list items will still occur if possible.</p>
2648
2649 <p>For another possibility see the -fs flag in <a href="#Skipping-Selected-Sections-of-Code">&quot;Skipping Selected Sections of Code&quot;</a>.</p>
2650
2651 <dl>
2652
2653 <dt id="boc---break-at-old-comma-breakpoints"><b>-boc</b>, <b>--break-at-old-comma-breakpoints</b></dt>
2654 <dd>
2655
2656 <p>The <b>-boc</b> flag is another way to prevent comma-separated lists from being reformatted. Using <b>-boc</b> on the above example, plus additional flags to retain the original style, yields</p>
2657
2658 <pre><code>    # perltidy -boc -lp -pt=2 -vt=1 -vtc=1
2659     my @list = (1,
2660                 1, 1,
2661                 1, 2, 1,
2662                 1, 3, 3, 1,
2663                 1, 4, 6, 4, 1,);</code></pre>
2664
2665 <p>A disadvantage of this flag compared to the methods discussed above is that all tables in the file must already be nicely formatted.</p>
2666
2667 </dd>
2668 <dt id="mft-n---maximum-fields-per-table-n"><b>-mft=n</b>, <b>--maximum-fields-per-table=n</b></dt>
2669 <dd>
2670
2671 <p>If the computed number of fields for any table exceeds <b>n</b>, then it will be reduced to <b>n</b>. The default value for <b>n</b> is a large number, 40. While this value should probably be left unchanged as a general rule, it might be used on a small section of code to force a list to have a particular number of fields per line, and then either the <b>-boc</b> flag could be used to retain this formatting, or a single comment could be introduced somewhere to freeze the formatting in future applications of perltidy.</p>
2672
2673 <pre><code>    # perltidy -mft=2
2674     @month_of_year = (
2675         &#39;Jan&#39;, &#39;Feb&#39;,
2676         &#39;Mar&#39;, &#39;Apr&#39;,
2677         &#39;May&#39;, &#39;Jun&#39;,
2678         &#39;Jul&#39;, &#39;Aug&#39;,
2679         &#39;Sep&#39;, &#39;Oct&#39;,
2680         &#39;Nov&#39;, &#39;Dec&#39;
2681     );</code></pre>
2682
2683 </dd>
2684 <dt id="cab-n---comma-arrow-breakpoints-n"><b>-cab=n</b>, <b>--comma-arrow-breakpoints=n</b></dt>
2685 <dd>
2686
2687 <p>A comma which follows a comma arrow, &#39;=&gt;&#39;, is given special consideration. In a long list, it is common to break at all such commas. This parameter can be used to control how perltidy breaks at these commas. (However, it will have no effect if old comma breaks are being forced because <b>-boc</b> is used). The possible values of <b>n</b> are:</p>
2688
2689 <pre><code> n=0 break at all commas after =&gt;
2690  n=1 stable: break at all commas after =&gt; if container is open,
2691      EXCEPT FOR one-line containers
2692  n=2 break at all commas after =&gt;, BUT try to form the maximum
2693      one-line container lengths
2694  n=3 do not treat commas after =&gt; specially at all
2695  n=4 break everything: like n=0 but ALSO break a short container with
2696      a =&gt; not followed by a comma when -vt=0 is used
2697  n=5 stable: like n=1 but ALSO break at open one-line containers when
2698      -vt=0 is used (default)</code></pre>
2699
2700 <p>For example, given the following single line, perltidy by default will not add any line breaks because it would break the existing one-line container:</p>
2701
2702 <pre><code>    bless { B =&gt; $B, Root =&gt; $Root } =&gt; $package;</code></pre>
2703
2704 <p>Using <b>-cab=0</b> will force a break after each comma-arrow item:</p>
2705
2706 <pre><code>    # perltidy -cab=0:
2707     bless {
2708         B    =&gt; $B,
2709         Root =&gt; $Root
2710     } =&gt; $package;</code></pre>
2711
2712 <p>If perltidy is subsequently run with this container broken, then by default it will break after each &#39;=&gt;&#39; because the container is now broken. To reform a one-line container, the parameter <b>-cab=2</b> could be used.</p>
2713
2714 <p>The flag <b>-cab=3</b> can be used to prevent these commas from being treated specially. In this case, an item such as &quot;01&quot; =&gt; 31 is treated as a single item in a table. The number of fields in this table will be determined by the same rules that are used for any other table. Here is an example.</p>
2715
2716 <pre><code>    # perltidy -cab=3
2717     my %last_day = (
2718         &quot;01&quot; =&gt; 31, &quot;02&quot; =&gt; 29, &quot;03&quot; =&gt; 31, &quot;04&quot; =&gt; 30,
2719         &quot;05&quot; =&gt; 31, &quot;06&quot; =&gt; 30, &quot;07&quot; =&gt; 31, &quot;08&quot; =&gt; 31,
2720         &quot;09&quot; =&gt; 30, &quot;10&quot; =&gt; 31, &quot;11&quot; =&gt; 30, &quot;12&quot; =&gt; 31
2721     );</code></pre>
2722
2723 </dd>
2724 </dl>
2725
2726 <h2 id="Retaining-or-Ignoring-Existing-Line-Breaks">Retaining or Ignoring Existing Line Breaks</h2>
2727
2728 <p>Several additional parameters are available for controlling the extent to which line breaks in the input script influence the output script. In most cases, the default parameter values are set so that, if a choice is possible, the output style follows the input style. For example, if a short logical container is broken in the input script, then the default behavior is for it to remain broken in the output script.</p>
2729
2730 <p>Most of the parameters in this section would only be required for a one-time conversion of a script from short container lengths to longer container lengths. The opposite effect, of converting long container lengths to shorter lengths, can be obtained by temporarily using a short maximum line length.</p>
2731
2732 <dl>
2733
2734 <dt id="bol---break-at-old-logical-breakpoints"><b>-bol</b>, <b>--break-at-old-logical-breakpoints</b></dt>
2735 <dd>
2736
2737 <p>By default, if a logical expression is broken at a <code>&amp;&amp;</code>, <code>||</code>, <code>and</code>, or <code>or</code>, then the container will remain broken. Also, breaks at internal keywords <code>if</code> and <code>unless</code> will normally be retained. To prevent this, and thus form longer lines, use <b>-nbol</b>.</p>
2738
2739 <p>Please note that this flag does not duplicate old logical breakpoints. They are merely used as a hint with this flag that a statement should remain broken. Without this flag, perltidy will normally try to combine relatively short expressions into a single line.</p>
2740
2741 <p>For example, given this snippet:</p>
2742
2743 <pre><code>    return unless $cmd = $cmd || ($dot
2744         &amp;&amp; $Last_Shell) || &amp;prompt(&#39;|&#39;);
2745
2746     # perltidy -bol [default]
2747     return
2748       unless $cmd = $cmd
2749       || ( $dot
2750         &amp;&amp; $Last_Shell )
2751       || &amp;prompt(&#39;|&#39;);
2752
2753     # perltidy -nbol
2754     return unless $cmd = $cmd || ( $dot &amp;&amp; $Last_Shell ) || &amp;prompt(&#39;|&#39;);</code></pre>
2755
2756 </dd>
2757 <dt id="bom---break-at-old-method-breakpoints"><b>-bom</b>, <b>--break-at-old-method-breakpoints</b></dt>
2758 <dd>
2759
2760 <p>By default, a method call arrow <code>-&gt;</code> is considered a candidate for a breakpoint, but method chains will fill to the line width before a break is considered. With <b>-bom</b>, breaks before the arrow are preserved, so if you have preformatted a method chain:</p>
2761
2762 <pre><code>  my $q = $rs
2763     -&gt;related_resultset(&#39;CDs&#39;)
2764     -&gt;related_resultset(&#39;Tracks&#39;)
2765     -&gt;search({
2766       &#39;track.id&#39; =&gt; {-ident =&gt; &#39;none_search.id&#39;},
2767     })-&gt;as_query;</code></pre>
2768
2769 <p>It will <b>keep</b> these breaks, rather than become this:</p>
2770
2771 <pre><code>  my $q = $rs-&gt;related_resultset(&#39;CDs&#39;)-&gt;related_resultset(&#39;Tracks&#39;)-&gt;search({
2772       &#39;track.id&#39; =&gt; {-ident =&gt; &#39;none_search.id&#39;},
2773     })-&gt;as_query;</code></pre>
2774
2775 <p>This flag will also look for and keep a &#39;cuddled&#39; style of calls, in which lines begin with a closing paren followed by a call arrow, as in this example:</p>
2776
2777 <pre><code>  # perltidy -bom -wn
2778   my $q = $rs-&gt;related_resultset(
2779       &#39;CDs&#39;
2780   )-&gt;related_resultset(
2781       &#39;Tracks&#39;
2782   )-&gt;search( {
2783       &#39;track.id&#39; =&gt; { -ident =&gt; &#39;none_search.id&#39; },
2784   } )-&gt;as_query;</code></pre>
2785
2786 <p>You may want to include the <b>-weld-nested-containers</b> flag in this case to keep nested braces and parens together, as in the last line.</p>
2787
2788 </dd>
2789 <dt id="bos---break-at-old-semicolon-breakpoints"><b>-bos</b>, <b>--break-at-old-semicolon-breakpoints</b></dt>
2790 <dd>
2791
2792 <p>Semicolons are normally placed at the end of a statement. This means that formatted lines do not normally begin with semicolons. If the input stream has some lines which begin with semicolons, these can be retained by setting this flag. For example, consider the following two-line input snippet:</p>
2793
2794 <pre><code>  $z = sqrt($x**2 + $y**2)
2795   ;</code></pre>
2796
2797 <p>The default formatting will be:</p>
2798
2799 <pre><code>  $z = sqrt( $x**2 + $y**2 );</code></pre>
2800
2801 <p>The result using <b>perltidy -bos</b> keeps the isolated semicolon:</p>
2802
2803 <pre><code>  $z = sqrt( $x**2 + $y**2 )
2804     ;</code></pre>
2805
2806 <p>The default is not to do this, <b>-nbos</b>.</p>
2807
2808 </dd>
2809 <dt id="bok---break-at-old-keyword-breakpoints"><b>-bok</b>, <b>--break-at-old-keyword-breakpoints</b></dt>
2810 <dd>
2811
2812 <p>By default, perltidy will retain a breakpoint before keywords which may return lists, such as <code>sort</code> and &lt;map&gt;. This allows chains of these operators to be displayed one per line. Use <b>-nbok</b> to prevent retaining these breakpoints.</p>
2813
2814 </dd>
2815 <dt id="bot---break-at-old-ternary-breakpoints"><b>-bot</b>, <b>--break-at-old-ternary-breakpoints</b></dt>
2816 <dd>
2817
2818 <p>By default, if a conditional (ternary) operator is broken at a <code>:</code>, then it will remain broken. To prevent this, and thereby form longer lines, use <b>-nbot</b>.</p>
2819
2820 </dd>
2821 <dt id="boa---break-at-old-attribute-breakpoints"><b>-boa</b>, <b>--break-at-old-attribute-breakpoints</b></dt>
2822 <dd>
2823
2824 <p>By default, if an attribute list is broken at a <code>:</code> in the source file, then it will remain broken. For example, given the following code, the line breaks at the &#39;:&#39;s will be retained:</p>
2825
2826 <pre><code>                    my @field
2827                       : field
2828                       : Default(1)
2829                       : Get(&#39;Name&#39; =&gt; &#39;foo&#39;) : Set(&#39;Name&#39;);</code></pre>
2830
2831 <p>If the attributes are on a single line in the source code then they will remain on a single line if possible.</p>
2832
2833 <p>To prevent this, and thereby always form longer lines, use <b>-nboa</b>.</p>
2834
2835 </dd>
2836 <dt id="Keeping-old-breakpoints-at-specific-token-types"><b>Keeping old breakpoints at specific token types</b></dt>
2837 <dd>
2838
2839 <p>It is possible to override the choice of line breaks made by perltidy, and force it to follow certain line breaks in the input stream, with these two parameters:</p>
2840
2841 <p><b>-kbb=s</b> or <b>--keep-old-breakpoints-before=s</b>, and</p>
2842
2843 <p><b>-kba=s</b> or <b>--keep-old-breakpoints-after=s</b></p>
2844
2845 <p>These parameters are each followed by a quoted string, <b>s</b>, containing a list of token types (separated only by spaces). No more than one of each of these parameters should be specified, because repeating a command-line parameter always overwrites the previous one before perltidy ever sees it.</p>
2846
2847 <p>For example, -kbb=&#39;=&gt;&#39; means that if an input line begins with a &#39;=&gt;&#39; then the output script should also have a line break before that token.</p>
2848
2849 <p>For example, given the script:</p>
2850
2851 <pre><code>    method &#39;foo&#39;
2852       =&gt; [ Int, Int ]
2853       =&gt; sub {
2854         my ( $self, $x, $y ) = ( shift, @_ );
2855         ...;
2856       };
2857
2858     # perltidy [default]
2859     method &#39;foo&#39; =&gt; [ Int, Int ] =&gt; sub {
2860         my ( $self, $x, $y ) = ( shift, @_ );
2861         ...;
2862     };
2863
2864     # perltidy -kbb=&#39;=&gt;&#39;
2865     method &#39;foo&#39;
2866       =&gt; [ Int, Int ]
2867       =&gt; sub {
2868         my ( $self, $x, $y ) = ( shift, @_ );
2869         ...;
2870       };</code></pre>
2871
2872 <p>For the container tokens &#39;{&#39;, &#39;[&#39; and &#39;(&#39; and, their closing counterparts, use the token symbol. Thus, the command to keep a break after all opening parens is:</p>
2873
2874 <pre><code>   perltidy -kba=&#39;(&#39;</code></pre>
2875
2876 <p>It is possible to be more specific in matching parentheses by preceding them with a letter. The possible letters are &#39;k&#39;, &#39;K&#39;, &#39;f&#39;, &#39;F&#39;, &#39;w&#39;, and &#39;W&#39;, with these meanings (these are the same as used in the <b>--weld-nested-exclusion-list</b> and <b>--line-up-parentheses-exclusion-list</b> parameters):</p>
2877
2878 <pre><code> &#39;k&#39; matches if the previous nonblank token is a perl builtin keyword (such as &#39;if&#39;, &#39;while&#39;),
2879  &#39;K&#39; matches if &#39;k&#39; does not, meaning that the previous token is not a keyword.
2880  &#39;f&#39; matches if the previous token is a function other than a keyword.
2881  &#39;F&#39; matches if &#39;f&#39; does not.
2882  &#39;w&#39; matches if either &#39;k&#39; or &#39;f&#39; match.
2883  &#39;W&#39; matches if &#39;w&#39; does not.</code></pre>
2884
2885 <p>So for example the the following parameter will keep breaks after opening function call parens:</p>
2886
2887 <pre><code>   perltidy -kba=&#39;f(&#39;</code></pre>
2888
2889 <p><b>NOTE</b>: To match all opening curly braces, and no other opening tokens, please prefix the brace it with an asterisk, like this: &#39;*{&#39;. Otherwise a warning message will occur. This is necessary to avoid problems while the input scheme is being updated and generalized. A single bare curly brace previously matched all container tokens, and tentatively still does. Likewise, to match all closing curly braces, and no other closing tokens, use &#39;*}&#39;.</p>
2890
2891 </dd>
2892 <dt id="iob---ignore-old-breakpoints"><b>-iob</b>, <b>--ignore-old-breakpoints</b></dt>
2893 <dd>
2894
2895 <p>Use this flag to tell perltidy to ignore existing line breaks to the maximum extent possible. This will tend to produce the longest possible containers, regardless of type, which do not exceed the line length limit. But please note that this parameter has priority over all other parameters requesting that certain old breakpoints be kept.</p>
2896
2897 <p>To illustrate, consider the following input text:</p>
2898
2899 <pre><code>    has subcmds =&gt; (
2900         is =&gt; &#39;ro&#39;,
2901         default =&gt; sub { [] },
2902     );</code></pre>
2903
2904 <p>The default formatting will keep the container broken, giving</p>
2905
2906 <pre><code>    # perltidy [default]
2907     has subcmds =&gt; (
2908         is      =&gt; &#39;ro&#39;,
2909         default =&gt; sub { [] },
2910     );</code></pre>
2911
2912 <p>If old breakpoints are ignored, the list will be flattened:</p>
2913
2914 <pre><code>    # perltidy -iob
2915     has subcmds =&gt; ( is =&gt; &#39;ro&#39;, default =&gt; sub { [] }, );</code></pre>
2916
2917 <p>Besides flattening lists, this parameter also applies to lines broken at certain logical breakpoints such as &#39;if&#39; and &#39;or&#39;.</p>
2918
2919 <p>Even if this is parameter is not used globally, it provides a convenient way to flatten selected lists from within an editor.</p>
2920
2921 </dd>
2922 <dt id="kis---keep-interior-semicolons"><b>-kis</b>, <b>--keep-interior-semicolons</b></dt>
2923 <dd>
2924
2925 <p>Use the <b>-kis</b> flag to prevent breaking at a semicolon if there was no break there in the input file. Normally perltidy places a newline after each semicolon which terminates a statement unless several statements are contained within a one-line brace block. To illustrate, consider the following input lines:</p>
2926
2927 <pre><code>    dbmclose(%verb_delim); undef %verb_delim;
2928     dbmclose(%expanded); undef %expanded;</code></pre>
2929
2930 <p>The default is to break after each statement, giving</p>
2931
2932 <pre><code>    dbmclose(%verb_delim);
2933     undef %verb_delim;
2934     dbmclose(%expanded);
2935     undef %expanded;</code></pre>
2936
2937 <p>With <b>perltidy -kis</b> the multiple statements are retained:</p>
2938
2939 <pre><code>    dbmclose(%verb_delim); undef %verb_delim;
2940     dbmclose(%expanded);   undef %expanded;</code></pre>
2941
2942 <p>The statements are still subject to the specified value of <b>maximum-line-length</b> and will be broken if this maximum is exceeded.</p>
2943
2944 </dd>
2945 </dl>
2946
2947 <h2 id="Blank-Line-Control">Blank Line Control</h2>
2948
2949 <p>Blank lines can improve the readability of a script if they are carefully placed. Perltidy has several commands for controlling the insertion, retention, and removal of blank lines.</p>
2950
2951 <dl>
2952
2953 <dt id="fbl---freeze-blank-lines"><b>-fbl</b>, <b>--freeze-blank-lines</b></dt>
2954 <dd>
2955
2956 <p>Set <b>-fbl</b> if you want to the blank lines in your script to remain exactly as they are. The rest of the parameters in this section may then be ignored. (Note: setting the <b>-fbl</b> flag is equivalent to setting <b>-mbl=0</b> and <b>-kbl=2</b>).</p>
2957
2958 </dd>
2959 <dt id="bbc---blanks-before-comments"><b>-bbc</b>, <b>--blanks-before-comments</b></dt>
2960 <dd>
2961
2962 <p>A blank line will be introduced before a full-line comment. This is the default. Use <b>-nbbc</b> or <b>--noblanks-before-comments</b> to prevent such blank lines from being introduced.</p>
2963
2964 </dd>
2965 <dt id="blbs-n---blank-lines-before-subs-n"><b>-blbs=n</b>, <b>--blank-lines-before-subs=n</b></dt>
2966 <dd>
2967
2968 <p>The parameter <b>-blbs=n</b> requests that least <b>n</b> blank lines precede a sub definition which does not follow a comment and which is more than one-line long. The default is &lt;-blbs=1&gt;. <b>BEGIN</b> and <b>END</b> blocks are included.</p>
2969
2970 <p>The requested number of blanks statement will be inserted regardless of the value of <b>--maximum-consecutive-blank-lines=n</b> (<b>-mbl=n</b>) with the exception that if <b>-mbl=0</b> then no blanks will be output.</p>
2971
2972 <p>This parameter interacts with the value <b>k</b> of the parameter <b>--maximum-consecutive-blank-lines=k</b> (<b>-mbl=k</b>) as follows:</p>
2973
2974 <p>1. If <b>-mbl=0</b> then no blanks will be output. This allows all blanks to be suppressed with a single parameter. Otherwise,</p>
2975
2976 <p>2. If the number of old blank lines in the script is less than <b>n</b> then additional blanks will be inserted to make the total <b>n</b> regardless of the value of <b>-mbl=k</b>.</p>
2977
2978 <p>3. If the number of old blank lines in the script equals or exceeds <b>n</b> then this parameter has no effect, however the total will not exceed value specified on the <b>-mbl=k</b> flag.</p>
2979
2980 </dd>
2981 <dt id="blbp-n---blank-lines-before-packages-n"><b>-blbp=n</b>, <b>--blank-lines-before-packages=n</b></dt>
2982 <dd>
2983
2984 <p>The parameter <b>-blbp=n</b> requests that least <b>n</b> blank lines precede a package which does not follow a comment. The default is <b>-blbp=1</b>.</p>
2985
2986 <p>This parameter interacts with the value <b>k</b> of the parameter <b>--maximum-consecutive-blank-lines=k</b> (<b>-mbl=k</b>) in the same way as described for the previous item <b>-blbs=n</b>.</p>
2987
2988 </dd>
2989 <dt id="bbs---blanks-before-subs"><b>-bbs</b>, <b>--blanks-before-subs</b></dt>
2990 <dd>
2991
2992 <p>For compatibility with previous versions, <b>-bbs</b> or <b>--blanks-before-subs</b> is equivalent to <i>-blbp=1</i> and <i>-blbs=1</i>.</p>
2993
2994 <p>Likewise, <b>-nbbs</b> or <b>--noblanks-before-subs</b> is equivalent to <i>-blbp=0</i> and <i>-blbs=0</i>.</p>
2995
2996 </dd>
2997 <dt id="bbb---blanks-before-blocks"><b>-bbb</b>, <b>--blanks-before-blocks</b></dt>
2998 <dd>
2999
3000 <p>A blank line will be introduced before blocks of coding delimited by <b>for</b>, <b>foreach</b>, <b>while</b>, <b>until</b>, and <b>if</b>, <b>unless</b>, in the following circumstances:</p>
3001
3002 <ul>
3003
3004 <li><p>The block is not preceded by a comment.</p>
3005
3006 </li>
3007 <li><p>The block is not a one-line block.</p>
3008
3009 </li>
3010 <li><p>The number of consecutive non-blank lines at the current indentation depth is at least <b>-lbl</b> (see next section).</p>
3011
3012 </li>
3013 </ul>
3014
3015 <p>This is the default. The intention of this option is to introduce some space within dense coding. This is negated with <b>-nbbb</b> or <b>--noblanks-before-blocks</b>.</p>
3016
3017 </dd>
3018 <dt id="lbl-n---long-block-line-count-n"><b>-lbl=n</b> <b>--long-block-line-count=n</b></dt>
3019 <dd>
3020
3021 <p>This controls how often perltidy is allowed to add blank lines before certain block types (see previous section). The default is 8. Entering a value of <b>0</b> is equivalent to entering a very large number.</p>
3022
3023 </dd>
3024 <dt id="blao-i-or---blank-lines-after-opening-block-i"><b>-blao=i</b> or <b>--blank-lines-after-opening-block=i</b></dt>
3025 <dd>
3026
3027 <p>This control places a minimum of <b>i</b> blank lines <b>after</b> a line which <b>ends</b> with an opening block brace of a specified type. By default, this only applies to the block of a named <b>sub</b>, but this can be changed (see <b>-blaol</b> below). The default is not to do this (<b>i=0</b>).</p>
3028
3029 <p>Please see the note below on using the <b>-blao</b> and <b>-blbc</b> options.</p>
3030
3031 </dd>
3032 <dt id="blbc-i-or---blank-lines-before-closing-block-i"><b>-blbc=i</b> or <b>--blank-lines-before-closing-block=i</b></dt>
3033 <dd>
3034
3035 <p>This control places a minimum of <b>i</b> blank lines <b>before</b> a line which <b>begins</b> with a closing block brace of a specified type. By default, this only applies to the block of a named <b>sub</b>, but this can be changed (see <b>-blbcl</b> below). The default is not to do this (<b>i=0</b>).</p>
3036
3037 </dd>
3038 <dt id="blaol-s-or---blank-lines-after-opening-block-list-s"><b>-blaol=s</b> or <b>--blank-lines-after-opening-block-list=s</b></dt>
3039 <dd>
3040
3041 <p>The parameter <b>s</b> is a list of block type keywords to which the flag <b>-blao</b> should apply. The section <a href="#Specifying-Block-Types">&quot;Specifying Block Types&quot;</a> explains how to list block types.</p>
3042
3043 </dd>
3044 <dt id="blbcl-s-or---blank-lines-before-closing-block-list-s"><b>-blbcl=s</b> or <b>--blank-lines-before-closing-block-list=s</b></dt>
3045 <dd>
3046
3047 <p>This parameter is a list of block type keywords to which the flag <b>-blbc</b> should apply. The section <a href="#Specifying-Block-Types">&quot;Specifying Block Types&quot;</a> explains how to list block types.</p>
3048
3049 </dd>
3050 <dt id="Note-on-using-the--blao-and--blbc-options"><b>Note on using the</b> <b>-blao</b> and <b>-blbc</b> options.</dt>
3051 <dd>
3052
3053 <p>These blank line controls introduce a certain minimum number of blank lines in the text, but the final number of blank lines may be greater, depending on values of the other blank line controls and the number of old blank lines. A consequence is that introducing blank lines with these and other controls cannot be exactly undone, so some experimentation with these controls is recommended before using them.</p>
3054
3055 <p>For example, suppose that for some reason we decide to introduce one blank space at the beginning and ending of all blocks. We could do this using</p>
3056
3057 <pre><code>  perltidy -blao=2 -blbc=2 -blaol=&#39;*&#39; -blbcl=&#39;*&#39; filename</code></pre>
3058
3059 <p>Now suppose the script continues to be developed, but at some later date we decide we don&#39;t want these spaces after all. We might expect that running with the flags <b>-blao=0</b> and <b>-blbc=0</b> will undo them. However, by default perltidy retains single blank lines, so the blank lines remain.</p>
3060
3061 <p>We can easily fix this by telling perltidy to ignore old blank lines by including the added parameter <b>-kbl=0</b> and rerunning. Then the unwanted blank lines will be gone. However, this will cause all old blank lines to be ignored, perhaps even some that were added by hand to improve formatting. So please be cautious when using these parameters.</p>
3062
3063 </dd>
3064 <dt id="mbl-n---maximum-consecutive-blank-lines-n"><b>-mbl=n</b> <b>--maximum-consecutive-blank-lines=n</b></dt>
3065 <dd>
3066
3067 <p>This parameter specifies the maximum number of consecutive blank lines which will be output within code sections of a script. The default is n=1. If the input file has more than n consecutive blank lines, the number will be reduced to n except as noted above for the <b>-blbp</b> and <b>-blbs</b> parameters. If <b>n=0</b> then no blank lines will be output (unless all old blank lines are retained with the <b>-kbl=2</b> flag of the next section).</p>
3068
3069 <p>This flag obviously does not apply to pod sections, here-documents, and quotes.</p>
3070
3071 </dd>
3072 <dt id="kbl-n---keep-old-blank-lines-n"><b>-kbl=n</b>, <b>--keep-old-blank-lines=n</b></dt>
3073 <dd>
3074
3075 <p>The <b>-kbl=n</b> flag gives you control over how your existing blank lines are treated.</p>
3076
3077 <p>The possible values of <b>n</b> are:</p>
3078
3079 <pre><code> n=0 ignore all old blank lines
3080  n=1 stable: keep old blanks, but limited by the value of the B&lt;-mbl=n&gt; flag
3081  n=2 keep all old blank lines, regardless of the value of the B&lt;-mbl=n&gt; flag</code></pre>
3082
3083 <p>The default is <b>n=1</b>.</p>
3084
3085 </dd>
3086 <dt id="sob---swallow-optional-blank-lines"><b>-sob</b>, <b>--swallow-optional-blank-lines</b></dt>
3087 <dd>
3088
3089 <p>This is equivalent to <b>kbl=0</b> and is included for compatibility with previous versions.</p>
3090
3091 </dd>
3092 <dt id="nsob---noswallow-optional-blank-lines"><b>-nsob</b>, <b>--noswallow-optional-blank-lines</b></dt>
3093 <dd>
3094
3095 <p>This is equivalent to <b>kbl=1</b> and is included for compatibility with previous versions.</p>
3096
3097 </dd>
3098 </dl>
3099
3100 <p><b>Controls for blank lines around lines of consecutive keywords</b></p>
3101
3102 <p>The parameters in this section provide some control over the placement of blank lines within and around groups of statements beginning with selected keywords. These blank lines are called here <b>keyword group blanks</b>, and all of the parameters begin with <b>--keyword-group-blanks*</b>, or <b>-kgb*</b> for short. The default settings do not employ these controls but they can be enabled with the following parameters:</p>
3103
3104 <p><b>-kgbl=s</b> or <b>--keyword-group-blanks-list=s</b>; <b>s</b> is a quoted string of keywords</p>
3105
3106 <p><b>-kgbs=s</b> or <b>--keyword-group-blanks-size=s</b>; <b>s</b> gives the number of keywords required to form a group.</p>
3107
3108 <p><b>-kgbb=n</b> or <b>--keyword-group-blanks-before=n</b>; <b>n</b> = (0, 1, or 2) controls a leading blank</p>
3109
3110 <p><b>-kgba=n</b> or <b>--keyword-group-blanks-after=n</b>; <b>n</b> = (0, 1, or 2) controls a trailing blank</p>
3111
3112 <p><b>-kgbi</b> or <b>--keyword-group-blanks-inside</b> is a switch for adding blanks between subgroups</p>
3113
3114 <p><b>-kgbd</b> or <b>--keyword-group-blanks-delete</b> is a switch for removing initial blank lines between keywords</p>
3115
3116 <p><b>-kgbr=n</b> or <b>--keyword-group-blanks-repeat-count=n</b> can limit the number of times this logic is applied</p>
3117
3118 <p>In addition, the following abbreviations are available to for simplified usage:</p>
3119
3120 <p><b>-kgb</b> or <b>--keyword-group-blanks</b> is short for <b>-kgbb=2 -kgba=2 kgbi</b></p>
3121
3122 <p><b>-nkgb</b> or <b>--nokeyword-group-blanks</b>, is short for <b>-kgbb=1 -kgba=1 nkgbi</b></p>
3123
3124 <p>Before describing the meaning of the parameters in detail let us look at an example which is formatted with default parameter settings.</p>
3125
3126 <pre><code>        print &quot;Entering test 2\n&quot;;
3127         use Test;
3128         use Encode qw(from_to encode decode
3129           encode_utf8 decode_utf8
3130           find_encoding is_utf8);
3131         use charnames qw(greek);
3132         my @encodings     = grep( /iso-?8859/, Encode::encodings() );
3133         my @character_set = ( &#39;0&#39; .. &#39;9&#39;, &#39;A&#39; .. &#39;Z&#39;, &#39;a&#39; .. &#39;z&#39; );
3134         my @source        = qw(ascii iso8859-1 cp1250);
3135         my @destiny       = qw(cp1047 cp37 posix-bc);
3136         my @ebcdic_sets   = qw(cp1047 cp37 posix-bc);
3137         my $str           = join( &#39;&#39;, map( chr($_), 0x20 .. 0x7E ) );
3138         return unless ($str);</code></pre>
3139
3140 <p>using <b>perltidy -kgb</b> gives:</p>
3141
3142 <pre><code>        print &quot;Entering test 2\n&quot;;
3143                                       &lt;----------this blank controlled by -kgbb
3144         use Test;
3145         use Encode qw(from_to encode decode
3146           encode_utf8 decode_utf8
3147           find_encoding is_utf8);
3148         use charnames qw(greek);
3149                                       &lt;---------this blank controlled by -kgbi
3150         my @encodings     = grep( /iso-?8859/, Encode::encodings() );
3151         my @character_set = ( &#39;0&#39; .. &#39;9&#39;, &#39;A&#39; .. &#39;Z&#39;, &#39;a&#39; .. &#39;z&#39; );
3152         my @source        = qw(ascii iso8859-1 cp1250);
3153         my @destiny       = qw(cp1047 cp37 posix-bc);
3154         my @ebcdic_sets   = qw(cp1047 cp37 posix-bc);
3155         my $str           = join( &#39;&#39;, map( chr($_), 0x20 .. 0x7E ) );
3156                                       &lt;----------this blank controlled by -kgba
3157         return unless ($str);</code></pre>
3158
3159 <p>Blank lines have been introduced around the <b>my</b> and <b>use</b> sequences. What happened is that the default keyword list includes <b>my</b> and <b>use</b> but not <b>print</b> and <b>return</b>. So a continuous sequence of nine <b>my</b> and <b>use</b> statements was located. This number exceeds the default threshold of five, so blanks were placed before and after the entire group. Then, since there was also a subsequence of six <b>my</b> lines, a blank line was introduced to separate them.</p>
3160
3161 <p>Finer control over blank placement can be achieved by using the individual parameters rather than the <b>-kgb</b> flag. The individual controls are as follows.</p>
3162
3163 <p><b>-kgbl=s</b> or <b>--keyword-group-blanks-list=s</b>, where <b>s</b> is a quoted string, defines the set of keywords which will be formed into groups. The string is a space separated list of keywords. The default set is <b>s=&quot;use require local our my&quot;</b>, but any list of keywords may be used. Comment lines may also be included in a keyword group, even though they are not keywords. To include ordinary block comments, include the symbol <b>BC</b>. To include static block comments (which normally begin with &#39;##&#39;), include the symbol <b>SBC</b>.</p>
3164
3165 <p><b>-kgbs=s</b> or <b>--keyword-group-blanks-size=s</b>, where <b>s</b> is a string describing the number of consecutive keyword statements forming a group (Note: statements separated by blank lines in the input file are considered consecutive for purposes of this count). If <b>s</b> is an integer then it is the minimum number required for a group. A maximum value may also be given with the format <b>s=min.max</b>, where <b>min</b> is the minimum number and <b>max</b> is the maximum number, and the min and max values are separated by one or more dots. No groups will be found if the maximum is less than the minimum. The maximum is unlimited if not given. The default is <b>s=5</b>. Some examples:</p>
3166
3167 <pre><code>    s      min   max         number for group
3168     3      3     unlimited   3 or more
3169     1.1    1     1           1
3170     1..3   1     3           1 to 3
3171     1.0    1     0           (no match)</code></pre>
3172
3173 <p>There is no really good default value for this parameter. If it is set too small, then an excessive number of blank lines may be generated. However, some users may prefer reducing the value somewhat below the default, perhaps to <b>s=3</b>.</p>
3174
3175 <p><b>-kgbb=n</b> or <b>--keyword-group-blanks-before=n</b> specifies whether a blank should appear before the first line of the group, as follows:</p>
3176
3177 <pre><code>   n=0 =&gt; (delete) an existing blank line will be removed
3178    n=1 =&gt; (stable) no change to the input file is made  [DEFAULT]
3179    n=2 =&gt; (insert) a blank line is introduced if possible</code></pre>
3180
3181 <p><b>-kgba=n</b> or <b>--keyword-group-blanks-after=n</b> likewise specifies whether a blank should appear after the last line of the group, using the same scheme (0=delete, 1=stable, 2=insert).</p>
3182
3183 <p><b>-kgbi</b> or <b>--keyword-group-blanks-inside</b> controls the insertion of blank lines between the first and last statement of the entire group. If there is a continuous run of a single statement type with more than the minimum threshold number (as specified with <b>-kgbs=s</b>) then this switch causes a blank line be inserted between this subgroup and the others. In the example above this happened between the <b>use</b> and <b>my</b> statements.</p>
3184
3185 <p><b>-kgbd</b> or <b>--keyword-group-blanks-delete</b> controls the deletion of any blank lines that exist in the the group when it is first scanned. When statements are initially scanned, any existing blank lines are included in the collection. Any such orignial blank lines will be deleted before any other insertions are made when the parameter <b>-kgbd</b> is set. The default is not to do this, <b>-nkgbd</b>.</p>
3186
3187 <p><b>-kgbr=n</b> or <b>--keyword-group-blanks-repeat-count=n</b> specifies <b>n</b>, the maximum number of times this logic will be applied to any file. The special value <b>n=0</b> is the same as n=infinity which means it will be applied to an entire script [Default]. A value <b>n=1</b> could be used to make it apply just one time for example. This might be useful for adjusting just the <b>use</b> statements in the top part of a module for example.</p>
3188
3189 <p><b>-kgb</b> or <b>--keyword-group-blanks</b> is an abbreviation equivalent to setting <b>-kgbb=1 -kgba=1 -kgbi</b>. This turns on keyword group formatting with a set of default values.</p>
3190
3191 <p><b>-nkgb</b> or <b>--nokeyword-group-blanks</b> is equivalent to <b>-kgbb=0 -kgba nkgbi</b>. This flag turns off keyword group blank lines and is the default setting.</p>
3192
3193 <p>Here are a few notes about the functioning of this technique.</p>
3194
3195 <ul>
3196
3197 <li><p>These parameters are probably more useful as part of a major code reformatting operation rather than as a routine formatting operation.</p>
3198
3199 <p>In particular, note that deleting old blank lines with <b>-kgbd</b> is an irreversible operation so it should be applied with care. Existing blank lines may be serving an important role in controlling vertical alignment.</p>
3200
3201 </li>
3202 <li><p>Conflicts which arise among these <b>kgb*</b> parameters and other blank line controls are generally resolved by producing the maximum number of blank lines implied by any parameter.</p>
3203
3204 <p>For example, if the flags <b>--freeze-blank-lines</b>, or <b>--keep-old-blank-lines=2</b>, are set, then they have priority over any blank line deletion implied by the <b>-kgb</b> flags of this section, so no blank lines will be deleted.</p>
3205
3206 <p>For another example, if a keyword group ends at a <b>sub</b> and the flag <b>kgba=0</b> requests no blank line there, but we also have <b>--blank-lines-before-subs=2</b>, then two blank lines will still be introduced before the sub.</p>
3207
3208 </li>
3209 <li><p>The introduction of blank lines does not occur if it would conflict with other input controls or code validity. For example, a blank line will not be placed within a here-doc or within a section of code marked with format skipping comments. And in general, a blank line will only be introduced at the end of a group if the next statement is a line of code.</p>
3210
3211 </li>
3212 <li><p>The count which is used to determine the group size is not the number of lines but rather the total number of keywords which are found. Individual statements with a certain leading keyword may continue on multiple lines, but if any of these lines is nested more than one level deep then that group will be ended.</p>
3213
3214 </li>
3215 <li><p>The search for groups of lines with similar leading keywords is based on the input source, not the final formatted source. Consequently, if the source code is badly formatted, it would be best to make a first formatting pass without these options.</p>
3216
3217 </li>
3218 </ul>
3219
3220 <h2 id="Styles">Styles</h2>
3221
3222 <p>A style refers to a convenient collection of existing parameters.</p>
3223
3224 <dl>
3225
3226 <dt id="gnu---gnu-style"><b>-gnu</b>, <b>--gnu-style</b></dt>
3227 <dd>
3228
3229 <p><b>-gnu</b> gives an approximation to the GNU Coding Standards (which do not apply to perl) as they are sometimes implemented. At present, this style overrides the default style with the following parameters:</p>
3230
3231 <pre><code>    -lp -bl -noll -pt=2 -bt=2 -sbt=2 -icp</code></pre>
3232
3233 <p>To use this style with <b>-xlp</b> instead of <b>-lp</b> use <b>-gnu -xlp</b>.</p>
3234
3235 </dd>
3236 <dt id="pbp---perl-best-practices"><b>-pbp</b>, <b>--perl-best-practices</b></dt>
3237 <dd>
3238
3239 <p><b>-pbp</b> is an abbreviation for the parameters in the book <b>Perl Best Practices</b> by Damian Conway:</p>
3240
3241 <pre><code>    -l=78 -i=4 -ci=4 -st -se -vt=2 -cti=0 -pt=1 -bt=1 -sbt=1 -bbt=1 -nsfs -nolq
3242     -wbb=&quot;% + - * / x != == &gt;= &lt;= =~ !~ &lt; &gt; | &amp; =
3243           **= += *= &amp;= &lt;&lt;= &amp;&amp;= -= /= |= &gt;&gt;= ||= //= .= %= ^= x=&quot;</code></pre>
3244
3245 <p>Please note that this parameter set includes -st and -se flags, which make perltidy act as a filter on one file only. These can be overridden by placing <b>-nst</b> and/or <b>-nse</b> after the -pbp parameter.</p>
3246
3247 <p>Also note that the value of continuation indentation, -ci=4, is equal to the value of the full indentation, -i=4. It is recommended that the either (1) the parameter <b>-ci=2</b> be used instead, or the flag <b>-xci</b> be set. This will help show structure, particularly when there are ternary statements. The following snippet illustrates these options.</p>
3248
3249 <pre><code>    # perltidy -pbp
3250     $self-&gt;{_text} = (
3251          !$section        ? &#39;&#39;
3252         : $type eq &#39;item&#39; ? &quot;the $section entry&quot;
3253         :                   &quot;the section on $section&quot;
3254         )
3255         . (
3256         $page
3257         ? ( $section ? &#39; in &#39; : &#39;&#39; ) . &quot;the $page$page_ext manpage&quot;
3258         : &#39; elsewhere in this document&#39;
3259         );
3260
3261     # perltidy -pbp -ci=2
3262     $self-&gt;{_text} = (
3263          !$section        ? &#39;&#39;
3264         : $type eq &#39;item&#39; ? &quot;the $section entry&quot;
3265         :                   &quot;the section on $section&quot;
3266       )
3267       . (
3268         $page
3269         ? ( $section ? &#39; in &#39; : &#39;&#39; ) . &quot;the $page$page_ext manpage&quot;
3270         : &#39; elsewhere in this document&#39;
3271       );
3272
3273     # perltidy -pbp -xci
3274     $self-&gt;{_text} = (
3275          !$section        ? &#39;&#39;
3276         : $type eq &#39;item&#39; ? &quot;the $section entry&quot;
3277         :                   &quot;the section on $section&quot;
3278         )
3279         . ( $page
3280             ? ( $section ? &#39; in &#39; : &#39;&#39; ) . &quot;the $page$page_ext manpage&quot;
3281             : &#39; elsewhere in this document&#39;
3282         );</code></pre>
3283
3284 <p>The <b>-xci</b> flag was developed after the <b>-pbp</b> parameters were published so you need to include it separately.</p>
3285
3286 </dd>
3287 <dt id="One-line-blocks"><b>One-line blocks</b></dt>
3288 <dd>
3289
3290 <p>There are a few points to note regarding one-line blocks. A one-line block is something like this,</p>
3291
3292 <pre><code>    if ( -e $file ) { print &quot;&#39;$file&#39; exists\n&quot; }</code></pre>
3293
3294 <p>where the contents within the curly braces is short enough to fit on a single line.</p>
3295
3296 <p>With few exceptions, perltidy retains existing one-line blocks, if it is possible within the line-length constraint, but it does not attempt to form new ones. In other words, perltidy will try to follow the one-line block style of the input file.</p>
3297
3298 <p>If an existing one-line block is longer than the maximum line length, however, it will be broken into multiple lines. When this happens, perltidy checks for and adds any optional terminating semicolon (unless the <b>-nasc</b> option is used) if the block is a code block.</p>
3299
3300 <p>The main exception is that perltidy will attempt to form new one-line blocks following the keywords <code>map</code>, <code>eval</code>, and <code>sort</code>, because these code blocks are often small and most clearly displayed in a single line.</p>
3301
3302 <p>One-line block rules can conflict with the cuddled-else option. When the cuddled-else option is used, perltidy retains existing one-line blocks, even if they do not obey cuddled-else formatting.</p>
3303
3304 <p>Occasionally, when one-line blocks get broken because they exceed the available line length, the formatting will violate the requested brace style. If this happens, reformatting the script a second time should correct the problem.</p>
3305
3306 <p>Sometimes it might be desirable to convert a script to have one-line blocks whenever possible. Although there is currently no flag for this, a simple workaround is to execute perltidy twice, once with the flag <b>-noadd-newlines</b> and then once again with normal parameters, like this:</p>
3307
3308 <pre><code>     cat infile | perltidy -nanl | perltidy &gt;outfile</code></pre>
3309
3310 <p>When executed on this snippet</p>
3311
3312 <pre><code>    if ( $? == -1 ) {
3313         die &quot;failed to execute: $!\n&quot;;
3314     }
3315     if ( $? == -1 ) {
3316         print &quot;Had enough.\n&quot;;
3317         die &quot;failed to execute: $!\n&quot;;
3318     }</code></pre>
3319
3320 <p>the result is</p>
3321
3322 <pre><code>    if ( $? == -1 ) { die &quot;failed to execute: $!\n&quot;; }
3323     if ( $? == -1 ) {
3324         print &quot;Had enough.\n&quot;;
3325         die &quot;failed to execute: $!\n&quot;;
3326     }</code></pre>
3327
3328 <p>This shows that blocks with a single statement become one-line blocks.</p>
3329
3330 </dd>
3331 <dt id="olbs-n---one-line-block-semicolons-n"><b>-olbs=n</b>, <b>--one-line-block-semicolons=n</b></dt>
3332 <dd>
3333
3334 <p>This flag controls the placement of semicolons at the end of one-line blocks. Semicolons are optional before a closing block brace, and frequently they are omitted at the end of a one-line block containing just a single statement. By default, perltidy follows the input file regarding these semicolons, but this behavior can be controlled by this flag. The values of n are:</p>
3335
3336 <pre><code>  n=0 remove terminal semicolons in one-line blocks having a single statement
3337   n=1 stable; keep input file placement of terminal semicolons [DEFAULT ]
3338   n=2 add terminal semicolons in all one-line blocks</code></pre>
3339
3340 <p>Note that the <b>n=2</b> option has no effect if adding semicolons is prohibited with the <b>-nasc</b> flag. Also not that while <b>n=2</b> adds missing semicolons to all one-line blocks, regardless of complexity, the <b>n=0</b> option only removes ending semicolons which terminate one-line blocks containing just one semicolon. So these two options are not exact inverses.</p>
3341
3342 </dd>
3343 <dt id="olbn-n---one-line-block-nesting-n"><b>-olbn=n</b>, <b>--one-line-block-nesting=n</b></dt>
3344 <dd>
3345
3346 <p>Nested one-line blocks are lines with code blocks which themselves contain code blocks. For example, the following line is a nested one-line block.</p>
3347
3348 <pre><code>         foreach (@list) { if ($_ eq $asked_for) { last } ++$found }</code></pre>
3349
3350 <p>The default behavior is to break such lines into multiple lines, but this behavior can be controlled with this flag. The values of n are:</p>
3351
3352 <pre><code>  n=0 break nested one-line blocks into multiple lines [DEFAULT]
3353   n=1 stable: keep existing nested-one line blocks intact</code></pre>
3354
3355 <p>For the above example, the default formatting (<b>-olbn=0</b>) is</p>
3356
3357 <pre><code>    foreach (@list) {
3358         if ( $_ eq $asked_for ) { last }
3359         ++$found;
3360     }</code></pre>
3361
3362 <p>If the parameter <b>-olbn=1</b> is given, then the line will be left intact if it is a single line in the source, or it will be broken into multiple lines if it is broken in multiple lines in the source.</p>
3363
3364 </dd>
3365 </dl>
3366
3367 <h2 id="Controlling-Vertical-Alignment">Controlling Vertical Alignment</h2>
3368
3369 <p>Vertical alignment refers to lining up certain symbols in a list of consecutive similar lines to improve readability. For example, the &quot;fat commas&quot; are aligned in the following statement:</p>
3370
3371 <pre><code>        $data = $pkg-&gt;new(
3372             PeerAddr =&gt; join( &quot;.&quot;, @port[ 0 .. 3 ] ),
3373             PeerPort =&gt; $port[4] * 256 + $port[5],
3374             Proto    =&gt; &#39;tcp&#39;
3375         );</code></pre>
3376
3377 <p>Vertical alignment can be completely turned off using the <b>-novalign</b> flag mentioned below. However, vertical alignment can be forced to stop and restart by selectively introducing blank lines. For example, a blank has been inserted in the following code to keep somewhat similar things aligned.</p>
3378
3379 <pre><code>    %option_range = (
3380         &#39;format&#39;             =&gt; [ &#39;tidy&#39;, &#39;html&#39;, &#39;user&#39; ],
3381         &#39;output-line-ending&#39; =&gt; [ &#39;dos&#39;,  &#39;win&#39;,  &#39;mac&#39;, &#39;unix&#39; ],
3382         &#39;character-encoding&#39; =&gt; [ &#39;none&#39;, &#39;utf8&#39; ],
3383
3384         &#39;block-brace-tightness&#39;    =&gt; [ 0, 2 ],
3385         &#39;brace-tightness&#39;          =&gt; [ 0, 2 ],
3386         &#39;paren-tightness&#39;          =&gt; [ 0, 2 ],
3387         &#39;square-bracket-tightness&#39; =&gt; [ 0, 2 ],
3388     );</code></pre>
3389
3390 <p>Vertical alignment is implemented by locally increasing an existing blank space to produce alignment with an adjacent line. It cannot occur if there is no blank space to increase. So if a particular space is removed by one of the existing controls then vertical alignment cannot occur. Likewise, if a space is added with one of the controls, then vertical alignment might occur.</p>
3391
3392 <p>For example,</p>
3393
3394 <pre><code>        # perltidy -nwls=&#39;=&gt;&#39;
3395         $data = $pkg-&gt;new(
3396             PeerAddr=&gt; join( &quot;.&quot;, @port[ 0 .. 3 ] ),
3397             PeerPort=&gt; $port[4] * 256 + $port[5],
3398             Proto=&gt; &#39;tcp&#39;
3399         );</code></pre>
3400
3401 <dl>
3402
3403 <dt id="Completely-turning-off-vertical-alignment-with--novalign"><b>Completely turning off vertical alignment with -novalign</b></dt>
3404 <dd>
3405
3406 <p>The default is to use vertical alignment, but bertical alignment can be completely turned of with the <b>-novalign</b> flag.</p>
3407
3408 <p>A lower level of control of vertical alignment is possible with three parameters <b>-vc</b>, <b>-vsc</b>, and <b>-vbc</b>. These independently control alignment of code, side comments and block comments. They are described in the next section.</p>
3409
3410 <p>The parameter <b>-valign</b> is in fact an alias for <b>-vc -vsc -vbc</b>, and its negative <b>-novalign</b> is an alias for <b>-nvc -nvsc -nvbc</b>.</p>
3411
3412 </dd>
3413 <dt id="Controlling-code-alignment-with---valign-code-or--vc"><b>Controlling code alignment with --valign-code or -vc</b></dt>
3414 <dd>
3415
3416 <p>The <b>-vc</b> flag enables alignment of code symbols such as <b>=</b>. The default is <b>-vc</b>. For detailed control of which symbols to align, see the <b>-valign-exclude-list</b> parameter below.</p>
3417
3418 </dd>
3419 <dt id="Controlling-side-comment-alignment-with---valign-side-comments-or--vsc"><b>Controlling side comment alignment with --valign-side-comments or -vsc</b></dt>
3420 <dd>
3421
3422 <p>The <b>-vsc</b> flag enables alignment of side comments and is enabled by default. If side comment aligment is disabled with <b>-nvsc</b> they will appear at a fixed space from the preceding code token. The default is <b>-vsc</b></p>
3423
3424 </dd>
3425 <dt id="Controlling-block-comment-alignment-with---valign-block-comments-or--vbc"><b>Controlling block comment alignment with --valign-block-comments or -vbc</b></dt>
3426 <dd>
3427
3428 <p>When <b>-vbc</b> is enabled, block comments can become aligned for example if one comment of a consecutive sequence of comments becomes outdented due a length in excess of the maximum line length. If this occurs, the entire group of comments will remain aligned and be outdented by the same amount. This coordinated alignment will not occur if <b>-nvbc</b> is set. The default is <b>-vbc</b>.</p>
3429
3430 </dd>
3431 <dt id="Finer-alignment-control-with---valign-exclusion-list-s-or--vxl-s-and---valign-inclusion-list-s-or--vil-s"><b>Finer alignment control with --valign-exclusion-list=s or -vxl=s and --valign-inclusion-list=s or -vil=s</b></dt>
3432 <dd>
3433
3434 <p>More detailed control of alignment types is available with these two parameters. Most of the vertical alignments in typical programs occur at one of the tokens &#39;,&#39;, &#39;=&#39;, and &#39;=&gt;&#39;, but many other alignments are possible and are given in the following list:</p>
3435
3436 <pre><code>  = **= += *= &amp;= &lt;&lt;= &amp;&amp;= -= /= |= &gt;&gt;= ||= //= .= %= ^= x=
3437   { ( ? : , ; =&gt; &amp;&amp; || ~~ !~~ =~ !~ // &lt;=&gt; -&gt;
3438   if unless and or err for foreach while until</code></pre>
3439
3440 <p>These alignments are all enabled by default, but they can be selectively disabled by including one or more of these tokens in the space-separated list <b>valign-exclusion-list=s</b>. For example, the following would prevent alignment at <b>=</b> and <b>if</b>:</p>
3441
3442 <pre><code>  --valign-exclusion-list=&#39;= if&#39;</code></pre>
3443
3444 <p>If it is simpler to specify only the token types which are to be aligned, then include the types which are to be aligned in the list of <b>--valign-inclusion-list</b>. You may leave the <b>valign-exclusion-list</b> undefined, or use the special symbol <b>*</b> for the exclusion list. For example, the following parameters enable alignment only at commas and &#39;fat commas&#39;:</p>
3445
3446 <pre><code>  --valign-inclusion-list=&#39;, =&gt;&#39;
3447   --valign-exclusion-list=&#39;*&#39;     ( this is optional and may be omitted )</code></pre>
3448
3449 <p>These parameter lists should consist of space-separated tokens from the above list of possible alignment tokens, or a &#39;*&#39;. If an unrecognized token appears, it is simply ignored. And if a specific token is entered in both lists by mistake then the exclusion list has priority.</p>
3450
3451 <p>The default values of these parameters enable all alignments and are equivalent to</p>
3452
3453 <pre><code>  --valign-exclusion-list=&#39; &#39;
3454   --valign-inclusion-list=&#39;*&#39;</code></pre>
3455
3456 <p>To illustrate, consider the following snippet with default formatting</p>
3457
3458 <pre><code>    # perltidy
3459     $co_description = ($color) ? &#39;bold cyan&#39;  : &#39;&#39;;           # description
3460     $co_prompt      = ($color) ? &#39;bold green&#39; : &#39;&#39;;           # prompt
3461     $co_unused      = ($color) ? &#39;on_green&#39;   : &#39;reverse&#39;;    # unused</code></pre>
3462
3463 <p>To exclude all alignments except the equals (i.e., include only equals) we could use:</p>
3464
3465 <pre><code>    # perltidy -vil=&#39;=&#39;
3466     $co_description = ($color) ? &#39;bold cyan&#39; : &#39;&#39;;          # description
3467     $co_prompt      = ($color) ? &#39;bold green&#39; : &#39;&#39;;         # prompt
3468     $co_unused      = ($color) ? &#39;on_green&#39; : &#39;reverse&#39;;    # unused</code></pre>
3469
3470 <p>To exclude only the equals we could use:</p>
3471
3472 <pre><code>    # perltidy -vxl=&#39;=&#39;
3473     $co_description = ($color) ? &#39;bold cyan&#39; : &#39;&#39;;     # description
3474     $co_prompt = ($color) ? &#39;bold green&#39; : &#39;&#39;;         # prompt
3475     $co_unused = ($color) ? &#39;on_green&#39; : &#39;reverse&#39;;    # unused</code></pre>
3476
3477 <p>Notice in this last example that although only the equals alignment was excluded, the ternary alignments were also lost. This happens because the vertical aligner sweeps from left-to-right and usually stops if an important alignment cannot be made for some reason.</p>
3478
3479 <p>But also notice that side comments remain aligned because their alignment is controlled separately with the parameter <b>--valign-side_comments</b> described above.</p>
3480
3481 </dd>
3482 </dl>
3483
3484 <h2 id="Other-Controls">Other Controls</h2>
3485
3486 <dl>
3487
3488 <dt id="Deleting-selected-text"><b>Deleting selected text</b></dt>
3489 <dd>
3490
3491 <p>Perltidy can selectively delete comments and/or pod documentation. The command <b>-dac</b> or <b>--delete-all-comments</b> will delete all comments <b>and</b> all pod documentation, leaving just code and any leading system control lines.</p>
3492
3493 <p>The command <b>-dp</b> or <b>--delete-pod</b> will remove all pod documentation (but not comments).</p>
3494
3495 <p>Two commands which remove comments (but not pod) are: <b>-dbc</b> or <b>--delete-block-comments</b> and <b>-dsc</b> or <b>--delete-side-comments</b>. (Hanging side comments will be deleted with side comments here.)</p>
3496
3497 <p>The negatives of these commands also work, and are the defaults. When block comments are deleted, any leading &#39;hash-bang&#39; will be retained. Also, if the <b>-x</b> flag is used, any system commands before a leading hash-bang will be retained (even if they are in the form of comments).</p>
3498
3499 </dd>
3500 <dt id="Writing-selected-text-to-a-file"><b>Writing selected text to a file</b></dt>
3501 <dd>
3502
3503 <p>When perltidy writes a formatted text file, it has the ability to also send selected text to a file with a <i>.TEE</i> extension. This text can include comments and pod documentation.</p>
3504
3505 <p>The command <b>-tac</b> or <b>--tee-all-comments</b> will write all comments <b>and</b> all pod documentation.</p>
3506
3507 <p>The command <b>-tp</b> or <b>--tee-pod</b> will write all pod documentation (but not comments).</p>
3508
3509 <p>The commands which write comments (but not pod) are: <b>-tbc</b> or <b>--tee-block-comments</b> and <b>-tsc</b> or <b>--tee-side-comments</b>. (Hanging side comments will be written with side comments here.)</p>
3510
3511 <p>The negatives of these commands also work, and are the defaults.</p>
3512
3513 </dd>
3514 <dt id="Using-a-.perltidyrc-command-file"><b>Using a <i>.perltidyrc</i> command file</b></dt>
3515 <dd>
3516
3517 <p>If you use perltidy frequently, you probably won&#39;t be happy until you create a <i>.perltidyrc</i> file to avoid typing commonly-used parameters. Perltidy will first look in your current directory for a command file named <i>.perltidyrc</i>. If it does not find one, it will continue looking for one in other standard locations.</p>
3518
3519 <p>These other locations are system-dependent, and may be displayed with the command <code>perltidy -dpro</code>. Under Unix systems, it will first look for an environment variable <b>PERLTIDY</b>. Then it will look for a <i>.perltidyrc</i> file in the home directory, and then for a system-wide file <i>/usr/local/etc/perltidyrc</i>, and then it will look for <i>/etc/perltidyrc</i>. Note that these last two system-wide files do not have a leading dot. Further system-dependent information will be found in the INSTALL file distributed with perltidy.</p>
3520
3521 <p>Under Windows, perltidy will also search for a configuration file named perltidy.ini since Windows does not allow files with a leading period (.). Use <code>perltidy -dpro</code> to see the possible locations for your system. An example might be <i>C:\Documents and Settings\All Users\perltidy.ini</i>.</p>
3522
3523 <p>Another option is the use of the PERLTIDY environment variable. The method for setting environment variables depends upon the version of Windows that you are using. Instructions for Windows 95 and later versions can be found here:</p>
3524
3525 <p>http://www.netmanage.com/000/20021101_005_tcm21-6336.pdf</p>
3526
3527 <p>Under Windows NT / 2000 / XP the PERLTIDY environment variable can be placed in either the user section or the system section. The later makes the configuration file common to all users on the machine. Be sure to enter the full path of the configuration file in the value of the environment variable. Ex. PERLTIDY=C:\Documents and Settings\perltidy.ini</p>
3528
3529 <p>The configuration file is free format, and simply a list of parameters, just as they would be entered on a command line. Any number of lines may be used, with any number of parameters per line, although it may be easiest to read with one parameter per line. Comment text begins with a #, and there must also be a space before the # for side comments. It is a good idea to put complex parameters in either single or double quotes.</p>
3530
3531 <p>Here is an example of a <i>.perltidyrc</i> file:</p>
3532
3533 <pre><code>  # This is a simple of a .perltidyrc configuration file
3534   # This implements a highly spaced style
3535   -se    # errors to standard error output
3536   -w     # show all warnings
3537   -bl    # braces on new lines
3538   -pt=0  # parens not tight at all
3539   -bt=0  # braces not tight
3540   -sbt=0 # square brackets not tight</code></pre>
3541
3542 <p>The parameters in the <i>.perltidyrc</i> file are installed first, so any parameters given on the command line will have priority over them.</p>
3543
3544 <p>To avoid confusion, perltidy ignores any command in the .perltidyrc file which would cause some kind of dump and an exit. These are:</p>
3545
3546 <pre><code> -h -v -ddf -dln -dop -dsn -dtt -dwls -dwrs -ss</code></pre>
3547
3548 <p>There are several options may be helpful in debugging a <i>.perltidyrc</i> file:</p>
3549
3550 <ul>
3551
3552 <li><p>A very helpful command is <b>--dump-profile</b> or <b>-dpro</b>. It writes a list of all configuration filenames tested to standard output, and if a file is found, it dumps the content to standard output before exiting. So, to find out where perltidy looks for its configuration files, and which one if any it selects, just enter</p>
3553
3554 <pre><code>  perltidy -dpro</code></pre>
3555
3556 </li>
3557 <li><p>It may be simplest to develop and test configuration files with alternative names, and invoke them with <b>-pro=filename</b> on the command line. Then rename the desired file to <i>.perltidyrc</i> when finished.</p>
3558
3559 </li>
3560 <li><p>The parameters in the <i>.perltidyrc</i> file can be switched off with the <b>-npro</b> option.</p>
3561
3562 </li>
3563 <li><p>The commands <b>--dump-options</b>, <b>--dump-defaults</b>, <b>--dump-long-names</b>, and <b>--dump-short-names</b>, all described below, may all be helpful.</p>
3564
3565 </li>
3566 </ul>
3567
3568 </dd>
3569 <dt id="Creating-a-new-abbreviation"><b>Creating a new abbreviation</b></dt>
3570 <dd>
3571
3572 <p>A special notation is available for use in a <i>.perltidyrc</i> file for creating an abbreviation for a group of options. This can be used to create a shorthand for one or more styles which are frequently, but not always, used. The notation is to group the options within curly braces which are preceded by the name of the alias (without leading dashes), like this:</p>
3573
3574 <pre><code>        newword {
3575         -opt1
3576         -opt2
3577         }</code></pre>
3578
3579 <p>where <b>newword</b> is the abbreviation, and <b>opt1</b>, etc, are existing parameters <i>or other abbreviations</i>. The main syntax requirement is that the new abbreviation along with its opening curly brace must begin on a new line. Space before and after the curly braces is optional.</p>
3580
3581 <p>For a specific example, the following line</p>
3582
3583 <pre><code>        oneliner { --maximum-line-length=0 --noadd-newlines --noadd-terminal-newline}</code></pre>
3584
3585 <p>or equivalently with abbreviations</p>
3586
3587 <pre><code>        oneliner { -l=0 -nanl -natnl }</code></pre>
3588
3589 <p>could be placed in a <i>.perltidyrc</i> file to temporarily override the maximum line length with a large value, to temporarily prevent new line breaks from being added, and to prevent an extra newline character from being added the file. All other settings in the <i>.perltidyrc</i> file still apply. Thus it provides a way to format a long &#39;one liner&#39; when perltidy is invoked with</p>
3590
3591 <pre><code>        perltidy --oneliner ...</code></pre>
3592
3593 <p>(Either <code>-oneliner</code> or <code>--oneliner</code> may be used).</p>
3594
3595 </dd>
3596 <dt id="Skipping-leading-non-perl-commands-with--x-or---look-for-hash-bang">Skipping leading non-perl commands with <b>-x</b> or <b>--look-for-hash-bang</b></dt>
3597 <dd>
3598
3599 <p>If your script has leading lines of system commands or other text which are not valid perl code, and which are separated from the start of the perl code by a &quot;hash-bang&quot; line, ( a line of the form <code>#!...perl</code> ), you must use the <b>-x</b> flag to tell perltidy not to parse and format any lines before the &quot;hash-bang&quot; line. This option also invokes perl with a -x flag when checking the syntax. This option was originally added to allow perltidy to parse interactive VMS scripts, but it should be used for any script which is normally invoked with <code>perl -x</code>.</p>
3600
3601 <p>Please note: do not use this flag unless you are sure your script needs it. Parsing errors can occur if it does not have a hash-bang, or, for example, if the actual first hash-bang is in a here-doc. In that case a parsing error will occur because the tokenization will begin in the middle of the here-doc.</p>
3602
3603 </dd>
3604 <dt id="Making-a-file-unreadable"><b>Making a file unreadable</b></dt>
3605 <dd>
3606
3607 <p>The goal of perltidy is to improve the readability of files, but there are two commands which have the opposite effect, <b>--mangle</b> and <b>--extrude</b>. They are actually merely aliases for combinations of other parameters. Both of these strip all possible whitespace, but leave comments and pod documents, so that they are essentially reversible. The difference between these is that <b>--mangle</b> puts the fewest possible line breaks in a script while <b>--extrude</b> puts the maximum possible. Note that these options do not provided any meaningful obfuscation, because perltidy can be used to reformat the files. They were originally developed to help test the tokenization logic of perltidy, but they have other uses. One use for <b>--mangle</b> is the following:</p>
3608
3609 <pre><code>  perltidy --mangle myfile.pl -st | perltidy -o myfile.pl.new</code></pre>
3610
3611 <p>This will form the maximum possible number of one-line blocks (see next section), and can sometimes help clean up a badly formatted script.</p>
3612
3613 <p>A similar technique can be used with <b>--extrude</b> instead of <b>--mangle</b> to make the minimum number of one-line blocks.</p>
3614
3615 <p>Another use for <b>--mangle</b> is to combine it with <b>-dac</b> to reduce the file size of a perl script.</p>
3616
3617 </dd>
3618 <dt id="Debugging"><b>Debugging</b></dt>
3619 <dd>
3620
3621 <p>The following flags are available for debugging:</p>
3622
3623 <p><b>--dump-cuddled-block-list</b> or <b>-dcbl</b> will dump to standard output the internal hash of cuddled block types created by a <b>-cuddled-block-list</b> input string.</p>
3624
3625 <p><b>--dump-defaults</b> or <b>-ddf</b> will write the default option set to standard output and quit</p>
3626
3627 <p><b>--dump-profile</b> or <b>-dpro</b> will write the name of the current configuration file and its contents to standard output and quit.</p>
3628
3629 <p><b>--dump-options</b> or <b>-dop</b> will write current option set to standard output and quit.</p>
3630
3631 <p><b>--dump-long-names</b> or <b>-dln</b> will write all command line long names (passed to Get_options) to standard output and quit.</p>
3632
3633 <p><b>--dump-short-names</b> or <b>-dsn</b> will write all command line short names to standard output and quit.</p>
3634
3635 <p><b>--dump-token-types</b> or <b>-dtt</b> will write a list of all token types to standard output and quit.</p>
3636
3637 <p><b>--dump-want-left-space</b> or <b>-dwls</b> will write the hash %want_left_space to standard output and quit. See the section on controlling whitespace around tokens.</p>
3638
3639 <p><b>--dump-want-right-space</b> or <b>-dwrs</b> will write the hash %want_right_space to standard output and quit. See the section on controlling whitespace around tokens.</p>
3640
3641 <p><b>--no-memoize</b> or <b>-nmem</b> will turn of memoizing. Memoization can reduce run time when running perltidy repeatedly in a single process. It is on by default but can be deactivated for testing with <b>-nmem</b>.</p>
3642
3643 <p><b>--no-timestamp</b> or <b>-nts</b> will eliminate any time stamps in output files to prevent differences in dates from causing test installation scripts to fail. There are just a couple of places where timestamps normally occur. One is in the headers of html files, and another is when the <b>-cscw</b> option is selected. The default is to allow timestamps (<b>--timestamp</b> or <b>-ts</b>).</p>
3644
3645 <p><b>--file-size-order</b> or <b>-fso</b> will cause files to be processed in order of increasing size, when multiple files are being processed. This is useful during program development, when large numbers of files with varying sizes are processed, because it can reduce virtual memory usage.</p>
3646
3647 <p><b>--maximum-file-size-mb=n</b> or <b>-maxfs=n</b> specifies the maximum file size in megabytes that perltidy will attempt to format. This parameter is provided to avoid causing system problems by accidentally attempting to format an extremely large data file. Most perl scripts are less than about 2 MB in size. The integer <b>n</b> has a default value of 10, so perltidy will skip formatting files which have a size greater than 10 MB. The command to increase the limit to 20 MB for example would be</p>
3648
3649 <pre><code>  perltidy -maxfs=20</code></pre>
3650
3651 <p>This only applies to files specified by filename on the command line.</p>
3652
3653 <p><b>--maximum-level-errors=n</b> or <b>-maxle=n</b> specifies the maximum number of indentation level errors are allowed before perltidy skips formatting and just outputs a file verbatim. The default is <b>n=1</b>. This means that if the final indentation of a script differs from the starting indentation by more than 1 levels, the file will be output verbatim. To avoid formatting if there are any indentation level errors use -maxle=0. To skip this check you can either set n equal to a large number, such as <b>n=100</b>, or set <b>n=-1</b>.</p>
3654
3655 <p>For example, the following script has level error of 3 and will be output verbatim</p>
3656
3657 <pre><code>    Input and default output:
3658     {{{
3659
3660
3661     perltidy -maxle=100
3662     {
3663         {
3664             {</code></pre>
3665
3666 <p><b>--maximum-unexpected-errors=n</b> or <b>-maxue=n</b> specifies the maximum number of unexpected tokenization errors are allowed before formatting is skipped and a script is output verbatim. The intention is to avoid accidentally formatting a non-perl script, such as an html file for example. This check can be turned off by setting <b>n=0</b>.</p>
3667
3668 <p>A recommended value is <b>n=3</b>. However, the default is <b>n=0</b> (skip this check) to avoid causing problems with scripts which have extended syntaxes.</p>
3669
3670 <p><b>-DEBUG</b> will write a file with extension <i>.DEBUG</i> for each input file showing the tokenization of all lines of code.</p>
3671
3672 </dd>
3673 <dt id="Working-with-MakeMaker-AutoLoader-and-SelfLoader"><b>Working with MakeMaker, AutoLoader and SelfLoader</b></dt>
3674 <dd>
3675
3676 <p>The first $VERSION line of a file which might be eval&#39;d by MakeMaker is passed through unchanged except for indentation. Use <b>--nopass-version-line</b>, or <b>-npvl</b>, to deactivate this feature.</p>
3677
3678 <p>If the AutoLoader module is used, perltidy will continue formatting code after seeing an __END__ line. Use <b>--nolook-for-autoloader</b>, or <b>-nlal</b>, to deactivate this feature.</p>
3679
3680 <p>Likewise, if the SelfLoader module is used, perltidy will continue formatting code after seeing a __DATA__ line. Use <b>--nolook-for-selfloader</b>, or <b>-nlsl</b>, to deactivate this feature.</p>
3681
3682 </dd>
3683 <dt id="Working-around-problems-with-older-version-of-Perl"><b>Working around problems with older version of Perl</b></dt>
3684 <dd>
3685
3686 <p>Perltidy contains a number of rules which help avoid known subtleties and problems with older versions of perl, and these rules always take priority over whatever formatting flags have been set. For example, perltidy will usually avoid starting a new line with a bareword, because this might cause problems if <code>use strict</code> is active.</p>
3687
3688 <p>There is no way to override these rules.</p>
3689
3690 </dd>
3691 </dl>
3692
3693 <h1 id="HTML-OPTIONS">HTML OPTIONS</h1>
3694
3695 <dl>
3696
3697 <dt id="The--html-master-switch">The <b>-html</b> master switch</dt>
3698 <dd>
3699
3700 <p>The flag <b>-html</b> causes perltidy to write an html file with extension <i>.html</i>. So, for example, the following command</p>
3701
3702 <pre><code>        perltidy -html somefile.pl</code></pre>
3703
3704 <p>will produce a syntax-colored html file named <i>somefile.pl.html</i> which may be viewed with a browser.</p>
3705
3706 <p><b>Please Note</b>: In this case, perltidy does not do any formatting to the input file, and it does not write a formatted file with extension <i>.tdy</i>. This means that two perltidy runs are required to create a fully reformatted, html copy of a script.</p>
3707
3708 </dd>
3709 <dt id="The--pre-flag-for-code-snippets">The <b>-pre</b> flag for code snippets</dt>
3710 <dd>
3711
3712 <p>When the <b>-pre</b> flag is given, only the pre-formatted section, within the &lt;PRE&gt; and &lt;/PRE&gt; tags, will be output. This simplifies inclusion of the output in other files. The default is to output a complete web page.</p>
3713
3714 </dd>
3715 <dt id="The--nnn-flag-for-line-numbering">The <b>-nnn</b> flag for line numbering</dt>
3716 <dd>
3717
3718 <p>When the <b>-nnn</b> flag is given, the output lines will be numbered.</p>
3719
3720 </dd>
3721 <dt id="The--toc-or---html-table-of-contents-flag">The <b>-toc</b>, or <b>--html-table-of-contents</b> flag</dt>
3722 <dd>
3723
3724 <p>By default, a table of contents to packages and subroutines will be written at the start of html output. Use <b>-ntoc</b> to prevent this. This might be useful, for example, for a pod document which contains a number of unrelated code snippets. This flag only influences the code table of contents; it has no effect on any table of contents produced by pod2html (see next item).</p>
3725
3726 </dd>
3727 <dt id="The--pod-or---pod2html-flag">The <b>-pod</b>, or <b>--pod2html</b> flag</dt>
3728 <dd>
3729
3730 <p>There are two options for formatting pod documentation. The default is to pass the pod through the Pod::Html module (which forms the basis of the pod2html utility). Any code sections are formatted by perltidy, and the results then merged. Note: perltidy creates a temporary file when Pod::Html is used; see <a href="#FILES">&quot;FILES&quot;</a>. Also, Pod::Html creates temporary files for its cache.</p>
3731
3732 <p>NOTE: Perltidy counts the number of <code>=cut</code> lines, and either moves the pod text to the top of the html file if there is one <code>=cut</code>, or leaves the pod text in its original order (interleaved with code) otherwise.</p>
3733
3734 <p>Most of the flags accepted by pod2html may be included in the perltidy command line, and they will be passed to pod2html. In some cases, the flags have a prefix <code>pod</code> to emphasize that they are for the pod2html, and this prefix will be removed before they are passed to pod2html. The flags which have the additional <code>pod</code> prefix are:</p>
3735
3736 <pre><code>   --[no]podheader --[no]podindex --[no]podrecurse --[no]podquiet
3737    --[no]podverbose --podflush</code></pre>
3738
3739 <p>The flags which are unchanged from their use in pod2html are:</p>
3740
3741 <pre><code>   --backlink=s --cachedir=s --htmlroot=s --libpods=s --title=s
3742    --podpath=s --podroot=s</code></pre>
3743
3744 <p>where &#39;s&#39; is an appropriate character string. Not all of these flags are available in older versions of Pod::Html. See your Pod::Html documentation for more information.</p>
3745
3746 <p>The alternative, indicated with <b>-npod</b>, is not to use Pod::Html, but rather to format pod text in italics (or whatever the stylesheet indicates), without special html markup. This is useful, for example, if pod is being used as an alternative way to write comments.</p>
3747
3748 </dd>
3749 <dt id="The--frm-or---frames-flag">The <b>-frm</b>, or <b>--frames</b> flag</dt>
3750 <dd>
3751
3752 <p>By default, a single html output file is produced. This can be changed with the <b>-frm</b> option, which creates a frame holding a table of contents in the left panel and the source code in the right side. This simplifies code browsing. Assume, for example, that the input file is <i>MyModule.pm</i>. Then, for default file extension choices, these three files will be created:</p>
3753
3754 <pre><code> MyModule.pm.html      - the frame
3755  MyModule.pm.toc.html  - the table of contents
3756  MyModule.pm.src.html  - the formatted source code</code></pre>
3757
3758 <p>Obviously this file naming scheme requires that output be directed to a real file (as opposed to, say, standard output). If this is not the case, or if the file extension is unknown, the <b>-frm</b> option will be ignored.</p>
3759
3760 </dd>
3761 <dt id="The--text-s-or---html-toc-extension-flag">The <b>-text=s</b>, or <b>--html-toc-extension</b> flag</dt>
3762 <dd>
3763
3764 <p>Use this flag to specify the extra file extension of the table of contents file when html frames are used. The default is &quot;toc&quot;. See <a href="#Specifying-File-Extensions">&quot;Specifying File Extensions&quot;</a>.</p>
3765
3766 </dd>
3767 <dt id="The--sext-s-or---html-src-extension-flag">The <b>-sext=s</b>, or <b>--html-src-extension</b> flag</dt>
3768 <dd>
3769
3770 <p>Use this flag to specify the extra file extension of the content file when html frames are used. The default is &quot;src&quot;. See <a href="#Specifying-File-Extensions">&quot;Specifying File Extensions&quot;</a>.</p>
3771
3772 </dd>
3773 <dt id="The--hent-or---html-entities-flag">The <b>-hent</b>, or <b>--html-entities</b> flag</dt>
3774 <dd>
3775
3776 <p>This flag controls the use of Html::Entities for html formatting. By default, the module Html::Entities is used to encode special symbols. This may not be the right thing for some browser/language combinations. Use --nohtml-entities or -nhent to prevent this.</p>
3777
3778 </dd>
3779 <dt id="Style-Sheets"><b>Style Sheets</b></dt>
3780 <dd>
3781
3782 <p>Style sheets make it very convenient to control and adjust the appearance of html pages. The default behavior is to write a page of html with an embedded style sheet.</p>
3783
3784 <p>An alternative to an embedded style sheet is to create a page with a link to an external style sheet. This is indicated with the <b>-css=filename</b>, where the external style sheet is <i>filename</i>. The external style sheet <i>filename</i> will be created if and only if it does not exist. This option is useful for controlling multiple pages from a single style sheet.</p>
3785
3786 <p>To cause perltidy to write a style sheet to standard output and exit, use the <b>-ss</b>, or <b>--stylesheet</b>, flag. This is useful if the style sheet could not be written for some reason, such as if the <b>-pre</b> flag was used. Thus, for example,</p>
3787
3788 <pre><code>  perltidy -html -ss &gt;mystyle.css</code></pre>
3789
3790 <p>will write a style sheet with the default properties to file <i>mystyle.css</i>.</p>
3791
3792 <p>The use of style sheets is encouraged, but a web page without a style sheets can be created with the flag <b>-nss</b>. Use this option if you must to be sure that older browsers (roughly speaking, versions prior to 4.0 of Netscape Navigator and Internet Explorer) can display the syntax-coloring of the html files.</p>
3793
3794 </dd>
3795 <dt id="Controlling-HTML-properties"><b>Controlling HTML properties</b></dt>
3796 <dd>
3797
3798 <p>Note: It is usually more convenient to accept the default properties and then edit the stylesheet which is produced. However, this section shows how to control the properties with flags to perltidy.</p>
3799
3800 <p>Syntax colors may be changed from their default values by flags of the either the long form, <b>-html-color-xxxxxx=n</b>, or more conveniently the short form, <b>-hcx=n</b>, where <b>xxxxxx</b> is one of the following words, and <b>x</b> is the corresponding abbreviation:</p>
3801
3802 <pre><code>      Token Type             xxxxxx           x
3803       ----------             --------         --
3804       comment                comment          c
3805       number                 numeric          n
3806       identifier             identifier       i
3807       bareword, function     bareword         w
3808       keyword                keyword          k
3809       quite, pattern         quote            q
3810       here doc text          here-doc-text    h
3811       here doc target        here-doc-target  hh
3812       punctuation            punctuation      pu
3813       parentheses            paren            p
3814       structural braces      structure        s
3815       semicolon              semicolon        sc
3816       colon                  colon            co
3817       comma                  comma            cm
3818       label                  label            j
3819       sub definition name    subroutine       m
3820       pod text               pod-text         pd</code></pre>
3821
3822 <p>A default set of colors has been defined, but they may be changed by providing values to any of the following parameters, where <b>n</b> is either a 6 digit hex RGB color value or an ascii name for a color, such as &#39;red&#39;.</p>
3823
3824 <p>To illustrate, the following command will produce an html file <i>somefile.pl.html</i> with &quot;aqua&quot; keywords:</p>
3825
3826 <pre><code>        perltidy -html -hck=00ffff somefile.pl</code></pre>
3827
3828 <p>and this should be equivalent for most browsers:</p>
3829
3830 <pre><code>        perltidy -html -hck=aqua somefile.pl</code></pre>
3831
3832 <p>Perltidy merely writes any non-hex names that it sees in the html file. The following 16 color names are defined in the HTML 3.2 standard:</p>
3833
3834 <pre><code>        black   =&gt; 000000,
3835         silver  =&gt; c0c0c0,
3836         gray    =&gt; 808080,
3837         white   =&gt; ffffff,
3838         maroon  =&gt; 800000,
3839         red     =&gt; ff0000,
3840         purple  =&gt; 800080,
3841         fuchsia =&gt; ff00ff,
3842         green   =&gt; 008000,
3843         lime    =&gt; 00ff00,
3844         olive   =&gt; 808000,
3845         yellow  =&gt; ffff00
3846         navy    =&gt; 000080,
3847         blue    =&gt; 0000ff,
3848         teal    =&gt; 008080,
3849         aqua    =&gt; 00ffff,</code></pre>
3850
3851 <p>Many more names are supported in specific browsers, but it is safest to use the hex codes for other colors. Helpful color tables can be located with an internet search for &quot;HTML color tables&quot;.</p>
3852
3853 <p>Besides color, two other character attributes may be set: bold, and italics. To set a token type to use bold, use the flag <b>--html-bold-xxxxxx</b> or <b>-hbx</b>, where <b>xxxxxx</b> or <b>x</b> are the long or short names from the above table. Conversely, to set a token type to NOT use bold, use <b>--nohtml-bold-xxxxxx</b> or <b>-nhbx</b>.</p>
3854
3855 <p>Likewise, to set a token type to use an italic font, use the flag <b>--html-italic-xxxxxx</b> or <b>-hix</b>, where again <b>xxxxxx</b> or <b>x</b> are the long or short names from the above table. And to set a token type to NOT use italics, use <b>--nohtml-italic-xxxxxx</b> or <b>-nhix</b>.</p>
3856
3857 <p>For example, to use bold braces and lime color, non-bold, italics keywords the following command would be used:</p>
3858
3859 <pre><code>        perltidy -html -hbs -hck=00FF00 -nhbk -hik somefile.pl</code></pre>
3860
3861 <p>The background color can be specified with <b>--html-color-background=n</b>, or <b>-hcbg=n</b> for short, where n is a 6 character hex RGB value. The default color of text is the value given to <b>punctuation</b>, which is black as a default.</p>
3862
3863 <p>Here are some notes and hints:</p>
3864
3865 <p>1. If you find a preferred set of these parameters, you may want to create a <i>.perltidyrc</i> file containing them. See the perltidy man page for an explanation.</p>
3866
3867 <p>2. Rather than specifying values for these parameters, it is probably easier to accept the defaults and then edit a style sheet. The style sheet contains comments which should make this easy.</p>
3868
3869 <p>3. The syntax-colored html files can be very large, so it may be best to split large files into smaller pieces to improve download times.</p>
3870
3871 </dd>
3872 </dl>
3873
3874 <h1 id="SOME-COMMON-INPUT-CONVENTIONS">SOME COMMON INPUT CONVENTIONS</h1>
3875
3876 <h2 id="Specifying-Block-Types">Specifying Block Types</h2>
3877
3878 <p>Several parameters which refer to code block types may be customized by also specifying an associated list of block types. The type of a block is the name of the keyword which introduces that block, such as <b>if</b>, <b>else</b>, or <b>sub</b>. An exception is a labeled block, which has no keyword, and should be specified with just a colon. To specify all blocks use <b>&#39;*&#39;</b>.</p>
3879
3880 <p>The keyword <b>sub</b> indicates a named sub. For anonymous subs, use the special keyword <b>asub</b>.</p>
3881
3882 <p>For example, the following parameter specifies <code>sub</code>, labels, <code>BEGIN</code>, and <code>END</code> blocks:</p>
3883
3884 <pre><code>   -cscl=&quot;sub : BEGIN END&quot;</code></pre>
3885
3886 <p>(the meaning of the -cscl parameter is described above.) Note that quotes are required around the list of block types because of the spaces. For another example, the following list specifies all block types for vertical tightness:</p>
3887
3888 <pre><code>   -bbvtl=&#39;*&#39;</code></pre>
3889
3890 <h2 id="Specifying-File-Extensions">Specifying File Extensions</h2>
3891
3892 <p>Several parameters allow default file extensions to be overridden. For example, a backup file extension may be specified with <b>-bext=ext</b>, where <b>ext</b> is some new extension. In order to provides the user some flexibility, the following convention is used in all cases to decide if a leading &#39;.&#39; should be used. If the extension <code>ext</code> begins with <code>A-Z</code>, <code>a-z</code>, or <code>0-9</code>, then it will be appended to the filename with an intermediate &#39;.&#39; (or perhaps a &#39;_&#39; on VMS systems). Otherwise, it will be appended directly.</p>
3893
3894 <p>For example, suppose the file is <i>somefile.pl</i>. For <code>-bext=old</code>, a &#39;.&#39; is added to give <i>somefile.pl.old</i>. For <code>-bext=.old</code>, no additional &#39;.&#39; is added, so again the backup file is <i>somefile.pl.old</i>. For <code>-bext=~</code>, then no dot is added, and the backup file will be <i>somefile.pl~</i> .</p>
3895
3896 <h1 id="SWITCHES-WHICH-MAY-BE-NEGATED">SWITCHES WHICH MAY BE NEGATED</h1>
3897
3898 <p>The following list shows all short parameter names which allow a prefix &#39;n&#39; to produce the negated form:</p>
3899
3900 <pre><code> D      anl    asbl   asc    ast    asu    atnl   aws    b      baa
3901  baao   bar    bbao   bbb    bbc    bbs    bl     bli    boa    boc
3902  bok    bol    bom    bos    bot    cblx   ce     conv   cs     csc
3903  cscb   cscw   dac    dbc    dcbl   dcsc   ddf    dln    dnl    dop
3904  dp     dpro   dsc    dsm    dsn    dtt    dwls   dwrs   dws    eos
3905  f      fll    fpva   frm    fs     fso    gcs    hbc    hbcm   hbco
3906  hbh    hbhh   hbi    hbj    hbk    hbm    hbn    hbp    hbpd   hbpu
3907  hbq    hbs    hbsc   hbv    hbw    hent   hic    hicm   hico   hih
3908  hihh   hii    hij    hik    him    hin    hip    hipd   hipu   hiq
3909  his    hisc   hiv    hiw    hsc    html   ibc    icb    icp    iob
3910  isbc   iscl   kgb    kgbd   kgbi   kis    lal    log    lop    lp
3911  lsl    mem    nib    ohbr   okw    ola    olc    oll    olq    opr
3912  opt    osbc   osbr   otr    ple    pod    pvl    q      sac    sbc
3913  sbl    scbb   schb   scp    scsb   sct    se     sfp    sfs    skp
3914  sob    sobb   sohb   sop    sosb   sot    ssc    st     sts    t
3915  tac    tbc    toc    tp     tqw    trp    ts     tsc    tso    vbc
3916  vc     vmll   vsc    w      wn     x      xci    xlp    xs</code></pre>
3917
3918 <p>Equivalently, the prefix &#39;no&#39; or &#39;no-&#39; on the corresponding long names may be used.</p>
3919
3920 <h1 id="LIMITATIONS">LIMITATIONS</h1>
3921
3922 <dl>
3923
3924 <dt id="Parsing-Limitations"><b>Parsing Limitations</b></dt>
3925 <dd>
3926
3927 <p>Perltidy should work properly on most perl scripts. It does a lot of self-checking, but still, it is possible that an error could be introduced and go undetected. Therefore, it is essential to make careful backups and to test reformatted scripts.</p>
3928
3929 <p>The main current limitation is that perltidy does not scan modules included with &#39;use&#39; statements. This makes it necessary to guess the context of any bare words introduced by such modules. Perltidy has good guessing algorithms, but they are not infallible. When it must guess, it leaves a message in the log file.</p>
3930
3931 <p>If you encounter a bug, please report it.</p>
3932
3933 </dd>
3934 <dt id="What-perltidy-does-not-parse-and-format"><b>What perltidy does not parse and format</b></dt>
3935 <dd>
3936
3937 <p>Perltidy indents but does not reformat comments and <code>qw</code> quotes. Perltidy does not in any way modify the contents of here documents or quoted text, even if they contain source code. (You could, however, reformat them separately). Perltidy does not format &#39;format&#39; sections in any way. And, of course, it does not modify pod documents.</p>
3938
3939 </dd>
3940 </dl>
3941
3942 <h1 id="FILES">FILES</h1>
3943
3944 <dl>
3945
3946 <dt id="Temporary-files"><b>Temporary files</b></dt>
3947 <dd>
3948
3949 <p>Under the -html option with the default --pod2html flag, a temporary file is required to pass text to Pod::Html. Unix systems will try to use the POSIX tmpnam() function. Otherwise the file <i>perltidy.TMP</i> will be temporarily created in the current working directory.</p>
3950
3951 </dd>
3952 <dt id="Special-files-when-standard-input-is-used"><b>Special files when standard input is used</b></dt>
3953 <dd>
3954
3955 <p>When standard input is used, the log file, if saved, is <i>perltidy.LOG</i>, and any errors are written to <i>perltidy.ERR</i> unless the <b>-se</b> flag is set. These are saved in the current working directory.</p>
3956
3957 </dd>
3958 <dt id="Files-overwritten"><b>Files overwritten</b></dt>
3959 <dd>
3960
3961 <p>The following file extensions are used by perltidy, and files with these extensions may be overwritten or deleted: <i>.ERR</i>, <i>.LOG</i>, <i>.TEE</i>, and/or <i>.tdy</i>, <i>.html</i>, and <i>.bak</i>, depending on the run type and settings.</p>
3962
3963 </dd>
3964 <dt id="Files-extensions-limitations"><b>Files extensions limitations</b></dt>
3965 <dd>
3966
3967 <p>Perltidy does not operate on files for which the run could produce a file with a duplicated file extension. These extensions include <i>.LOG</i>, <i>.ERR</i>, <i>.TEE</i>, and perhaps <i>.tdy</i> and <i>.bak</i>, depending on the run type. The purpose of this rule is to prevent generating confusing filenames such as <i>somefile.tdy.tdy.tdy</i>.</p>
3968
3969 </dd>
3970 </dl>
3971
3972 <h1 id="ERROR-HANDLING">ERROR HANDLING</h1>
3973
3974 <p>An exit value of 0, 1, or 2 is returned by perltidy to indicate the status of the result.</p>
3975
3976 <p>A exit value of 0 indicates that perltidy ran to completion with no error messages.</p>
3977
3978 <p>A non-zero exit value indicates some kind of problem was detected.</p>
3979
3980 <p>An exit value of 1 indicates that perltidy terminated prematurely, usually due to some kind of errors in the input parameters. This can happen for example if a parameter is misspelled or given an invalid value. Error messages in the standard error output will indicate the cause of any problem. If perltidy terminates prematurely then no output files will be produced.</p>
3981
3982 <p>An exit value of 2 indicates that perltidy was able to run to completion but there there are (1) warning messages in the standard error output related to parameter errors or problems and/or (2) warning messages in the perltidy error file(s) relating to possible syntax errors in one or more of the source script(s) being tidied. When multiple files are being processed, an error detected in any single file will produce this type of exit condition.</p>
3983
3984 <h1 id="SEE-ALSO">SEE ALSO</h1>
3985
3986 <p>perlstyle(1), Perl::Tidy(3)</p>
3987
3988 <h1 id="INSTALLATION">INSTALLATION</h1>
3989
3990 <p>The perltidy binary uses the Perl::Tidy module and is installed when that module is installed. The module name is case-sensitive. For example, the basic command for installing with cpanm is &#39;cpanm Perl::Tidy&#39;.</p>
3991
3992 <h1 id="VERSION">VERSION</h1>
3993
3994 <p>This man page documents perltidy version 20220217</p>
3995
3996 <h1 id="BUG-REPORTS">BUG REPORTS</h1>
3997
3998 <p>A list of current bugs and issues can be found at the CPAN site <a href="https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Tidy">https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Tidy</a></p>
3999
4000 <p>To report a new bug or problem, use the link on this page.</p>
4001
4002 <p>The source code repository is at <a href="https://github.com/perltidy/perltidy">https://github.com/perltidy/perltidy</a>.</p>
4003
4004 <h1 id="COPYRIGHT">COPYRIGHT</h1>
4005
4006 <p>Copyright (c) 2000-2022 by Steve Hancock</p>
4007
4008 <h1 id="LICENSE">LICENSE</h1>
4009
4010 <p>This package is free software; you can redistribute it and/or modify it under the terms of the &quot;GNU General Public License&quot;.</p>
4011
4012 <p>Please refer to the file &quot;COPYING&quot; for details.</p>
4013
4014 <h1 id="DISCLAIMER">DISCLAIMER</h1>
4015
4016 <p>This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</p>
4017
4018 <p>See the &quot;GNU General Public License&quot; for more details.</p>
4019
4020
4021 </body>
4022
4023 </html>
4024
4025