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