#!/home/grinnz/projects/cpandoc-browser/perls/5.42.0/bin/perl package main; use Perl::Tidy; my $arg_string = undef; # give Macs a chance to provide command line parameters if ( $^O =~ /Mac/ ) { $arg_string = MacPerl::Ask( 'Please enter @ARGV (-h for help)', defined( $ARGV[0] ) ? "\"$ARGV[0]\"" : "" ); } # Exit codes returned by perltidy: # 0 = no errors # 1 = perltidy could not run to completion due to errors # 2 = perltidy ran to completion with error messages exit Perl::Tidy::perltidy( argv => $arg_string ); __END__ =head1 NAME perltidy - a perl script indenter and reformatter =head1 SYNOPSIS perltidy [ options ] file1 file2 file3 ... (output goes to file1.tdy, file2.tdy, file3.tdy, ...) perltidy [ options ] file1 -o outfile perltidy [ options ] file1 -st >outfile perltidy [ options ] outfile =head1 DESCRIPTION Perltidy reads a perl script and writes an indented, reformatted script. The formatting process involves converting the script into a string of tokens, removing any non-essential whitespace, and then rewriting the string of tokens with whitespace using whatever rules are specified, or defaults. This happens in a series of operations which can be controlled with the parameters described in this document. Perltidy is a commandline frontend to the module Perl::Tidy. For documentation describing how to call the Perl::Tidy module from other applications see the separate documentation for Perl::Tidy. It is the file Perl::Tidy.pod in the source distribution. Many users will find enough information in L<"EXAMPLES"> to get started. New users may benefit from the short tutorial which can be found at http://perltidy.sourceforge.net/tutorial.html A convenient aid to systematically defining a set of style parameters can be found at http://perltidy.sourceforge.net/stylekey.html Perltidy can produce output on either of two modes, depending on the existence of an B<-html> flag. Without this flag, the output is passed through a formatter. The default formatting tries to follow the recommendations in perlstyle(1), but it can be controlled in detail with numerous input parameters, which are described in L<"FORMATTING OPTIONS">. Many style variations are possible, but it is worth noting that the default style is particularly convenient for working on chunks of code with a line editor because it is easy to select a sequence of lines with balanced containers, which is necessary for formatting a snippet of code with perltidy. When the B<-html> flag is given, the output is passed through an HTML formatter which is described in L<"HTML OPTIONS">. =head1 EXAMPLES Here are some example perltidy commands and their meanings: =over 4 =item * This will produce a file F containing the script reformatted using the default options, which approximate the style suggested in perlstyle(1). The source file F is unchanged. perltidy somefile.pl =item * Execute perltidy on all F<.pl> files in the current directory with the default options. The output will be in files with an appended F<.tdy> extension. For any file with an error, there will be a file with extension F<.ERR>. perltidy *.pl =item * Modify F and F in place, and backup the originals to F and F. If F and/or F already exist, they will be overwritten. perltidy -b file1.pl file2.pl =item * Same as the previous example except that the backup files F and F will be deleted if there are no errors. perltidy -b -bext='/' file1.pl file2.pl =item * Execute perltidy on file F, with 4 columns for each level of continuation indentation (B<-ci=4>) instead of the default 2 columns, so that it is the same as the default primary indentation (B<-i=4>). There will not be any tabs in the reformatted script, except for any which already exist in comments, pod documents, quotes, and here documents. Output will be F. perltidy -ci=4 somefile.pl =item * Same as the previous example, except that leading whitespace will be entabbed with one tab character per 4 spaces, and thus one tab for each indentation level. perltidy -ci=4 -et=4 somefile.pl =item * Execute perltidy on file F with all defaults except use "cuddled elses" (B<-ce>) and a maximum line length of 72 columns (B<-l=72>) instead of the default 80 columns. perltidy -ce -l=72 somefile.pl =item * Dump a table of comma-separated metrics for subroutines longer than 10 lines to F and immediately exit without formatting: perltidy -dbs -dbl=10 somefile.pl >blocks.csv =item * Dump a list of unused and reused lexical variable names to F: perltidy -duv somefile.pl >vars.txt =item * This will produce a file F containing the script with html markup. The output file will contain an embedded style sheet in the C<> section which may be edited to change the appearance. perltidy -html somefile.pl =item * This will produce a file F containing the script with html markup. This output file will contain a link to a separate style sheet file F. If the file F does not exist, it will be created. If it exists, it will not be overwritten. perltidy -html -css=mystyle.css somefile.pl =item * Write an html snippet with only the C<
> section to F.
This is useful when code snippets are being formatted for inclusion in a
larger web page.  No style sheet will be written in this case.

  perltidy -html -pre somefile.pl

=item *

Write a style sheet to F and exit.

  perltidy -html -ss >mystyle.css

=item *

Write html with a frame holding a table of contents and the source code.  The
output files will be F (the frame), F
(the table of contents), and F (the source code).

  perltidy -html -frm mymodule.pm

=back

=head1 OPTIONS - OVERVIEW

The entire command line is scanned for options, and they are processed
before any files are processed.  As a result, it does not matter
whether flags are before or after any filenames.  However, the relative
order of parameters is important, with later parameters overriding the
values of earlier parameters.

For most parameters, there is a long name and a short name.  The short
names are convenient for keyboard input, while the long names are
self-documenting and therefore useful in scripts.  B

Most parameters which serve as on/off flags can be negated with a
leading "n" (for the short name) or a leading "no" or "no-" (for the
long name).  For example, the flag to outdent long quotes is B<-olq>
or B<--outdent-long-quotes>.  The flag to skip this is B<-nolq>
or B<--nooutdent-long-quotes> or B<--no-outdent-long-quotes>.

Options may not be bundled together.  In other words, options B<-q> and
B<-g> may NOT be entered as B<-qg>.

=head2 I/O Control

The following parameters concern the files which are read and written.

=over 4

=item B<-h>,    B<--help>

Show summary of usage and exit.

=item B<-v>,    B<--version>

Show perltidy VERSION number and exit.

=item   B<-o>=filename,    B<--outfile>=filename

Name of the output file (only if a single input file is being
processed).  If no output file is specified, and output is not
redirected to the standard output (see B<-st>), the output will go to
F. [Note: - does not redirect to standard output. Use
B<-st> instead.]

=item   B<-st>,    B<--standard-output>

Perltidy must be able to operate on an arbitrarily large number of files
in a single run, with each output being directed to a different output
file.  Obviously this would conflict with outputting to the single
standard output device, so a special flag, B<-st>, is required to
request outputting to the standard output.  For example,

  perltidy somefile.pl -st >somefile.new.pl

This option may only be used if there is just a single input file.
The default is B<-nst> or B<--nostandard-output>.

=item   B<-se>,    B<--standard-error-output>

If perltidy detects an error when processing file F, its
default behavior is to write error messages to file F.
Use B<-se> to cause all error messages to be sent to the standard error
output stream instead.  This directive may be negated with B<-nse>.
Thus, you may place B<-se> in a F<.perltidyrc> and override it when
desired with B<-nse> on the command line.

=item   B<-oext>=ext,    B<--output-file-extension>=ext

Change the extension of the output file to be F instead of the
default F (or F in case the -B<-html> option is used).
See L<"Specifying File Extensions">.

=item   B<-opath>=path,    B<--output-path>=path

When perltidy creates a filename for an output file, by default it merely
appends an extension to the path and basename of the input file.  This
parameter causes the path to be changed to F instead.

The path should end in a valid path separator character, but perltidy will try
to add one if it is missing.

For example

 perltidy somefile.pl -opath=/tmp/

will produce F.  Otherwise, F will
appear in whatever directory contains F.

If the path contains spaces, it should be placed in quotes.

This parameter will be ignored if output is being directed to standard output,
or if it is being specified explicitly with the B<--outfile=s> parameter.

=item   B<-b>,    B<--backup-and-modify-in-place>

Modify the input file or files in-place and save the original with the
extension F<.bak>.  Any existing F<.bak> file will be deleted.  See next
item for changing the default backup extension, and for eliminating the
backup file altogether.

B: Writing back to the input file increases the risk of data loss
or corruption in the event of a software or hardware malfunction. Before using
the B<-b> parameter please be sure to have backups and verify that it works
correctly in your environment and operating system.

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

In particular, if you want to use both the B<-b> flag and the
B<--perl-best-practices> (B<-pbp>) flag, then you must put a
B<--nostandard-output> (B<-nst>) flag after the B<-pbp> flag because it contains a
B<--standard-output> flag as one of its components, which means that output
will go to the standard output stream.

=item   B<-bext>=ext,    B<--backup-file-extension>=ext

This parameter serves two purposes: (1) to change the extension of the backup
file to be something other than the default F<.bak>, and (2) to indicate
that no backup file should be saved.

To change the default extension to something other than F<.bak> see
L<"Specifying File Extensions">.

A backup file of the source is always written, but you can request that it
be deleted at the end of processing if there were no errors.  This is risky
unless the source code is being maintained with a source code control
system.

To indicate that the backup should be deleted include one forward slash,
B, in the extension.  If any text remains after the slash is removed
it will be used to define the backup file extension (which is always
created and only deleted if there were no errors).

Here are some examples:

  Parameter          Extension      Backup File Treatment
  -bext=bak         .bak            Keep (same as default behavior)
  -bext='/'         .bak            Delete if no errors
  -bext='/backup'   .backup         Delete if no errors
  -bext='original/' .original       Delete if no errors

=item B<-bm=s>,  B<--backup-method=s>

This parameter should not normally be used but is available in the event that
problems arise as a transition is made from an older implementation of the
backup logic to a newer implementation.  The newer implementation is the
default and is specified with B<-bm='copy'>. The older implementation is
specified with B<-bm='move'>.  The difference is that the older implementation
made the backup by moving the input file to the backup file, and the newer
implementation makes the backup by copying the input file.  The newer
implementation preserves the file system B value. This may avoid
problems with other software running simultaneously.  This change was made
as part of issue B at github.

=item B<-w>,    B<--warning-output>

Setting B<-w> causes any non-critical warning
messages to be reported as errors.  These include messages
about possible pod problems, possibly bad starting indentation level,
and cautions about indirect object usage.  The default, B<-nw> or
B<--nowarning-output>, is not to include these warnings.

=item B<-q>,    B<--quiet>

Deactivate error messages (for running under an editor).

For example, if you use a vi-style editor, such as vim, you may execute
perltidy as a filter from within the editor using something like

 :n1,n2!perltidy -q

where C represents the selected text.  Without the B<-q> flag,
any error message may mess up your screen, so be prepared to use your
"undo" key.

=item B<-log>,    B<--logfile>

Save the F<.LOG> file, which has many useful diagnostics.  Perltidy always
creates a F<.LOG> file, but by default it is deleted unless a program bug is
suspected.  Setting the B<-log> flag forces the log file to be saved.

=item B<-g=n>, B<--logfile-gap=n>

Set maximum interval between input code lines in the logfile.  This purpose of
this flag is to assist in debugging nesting errors.  The value of C is
optional.  If you set the flag B<-g> without the value of C, it will be
taken to be 1, meaning that every line will be written to the log file.  This
can be helpful if you are looking for a brace, paren, or bracket nesting error.

Setting B<-g> also causes the logfile to be saved, so it is not necessary to
also include B<-log>.

If no B<-g> flag is given, a value of 50 will be used, meaning that at least
every 50th line will be recorded in the logfile.  This helps prevent
excessively long log files.

Setting a negative value of C is the same as not setting B<-g> at all.

=item B<-npro>  B<--noprofile>

Ignore any F<.perltidyrc> command file.  Normally, perltidy looks first in
your current directory for a F<.perltidyrc> file of parameters.  (The format
is described below).  If it finds one, it applies those options to the
initial default values, and then it applies any that have been defined
on the command line.  If no F<.perltidyrc> file is found, it looks for one
in your home directory.

If you set the B<-npro> flag, perltidy will not look for this file.

=item B<-pro=filename> or  B<--profile=filename>

To simplify testing and switching .perltidyrc files, this command may be
used to specify a configuration file which will override the default
name of F<.perltidyrc>.  There must not be a space on either side of the
'=' sign.  For example, the line

   perltidy -pro=testcfg

would cause file F to be used instead of the
default F<.perltidyrc>.

A pathname begins with three dots, e.g. ".../.perltidyrc", indicates that
the file should be searched for starting in the current directory and
working upwards. This makes it easier to have multiple projects each with
their own .perltidyrc in their root directories.

=item B<-opt>,   B<--show-options>

Write a list of all options used to the F<.LOG> file.
Please see B<--dump-options> for a simpler way to do this.

=item B<-f>,   B<--force-read-binary>

Force perltidy to process binary files.  To avoid producing excessive
error messages, perltidy skips files identified by the system as non-text.
However, valid perl scripts containing binary data may sometimes be identified
as non-text, and this flag forces perltidy to process them.

=item B<-ast>,   B<--assert-tidy>

This flag asserts that the input and output code streams are identical, or in
other words that the input code is already 'tidy' according to the formatting
parameters.  If this is not the case, an error message noting this is produced.
This error message will cause the process to return a non-zero exit code.
The test for this is made by comparing an MD5 hash value for the input and
output code streams. This flag has no other effect on the functioning of
perltidy.  This might be useful for certain code maintenance operations.
Note: you will not see this message if you have error messages turned off with the
-quiet flag.

=item B<-asu>,   B<--assert-untidy>

This flag asserts that the input and output code streams are different, or in
other words that the input code is 'untidy' according to the formatting
parameters.  If this is not the case, an error message noting this is produced.
This flag has no other effect on the functioning of perltidy.

=item B<-tos=n>,   B<--timeout-in-seconds=n>

When the standard input supplies the input stream, and the input has not been
received within B seconds, perltidy will end with a timeout message.  The
intention is to catch a situation where perltidy is accidentally invoked
without a file to process and therefore waits for input from the system
standard input (stdin), which never arrives.  The default is B seconds.
This check can be turned off with B.

=back

=head1 FORMATTING OPTIONS

=head2 Basic Options

=over 4

=item B<-fmt=s>, B<--format=s>

If B<--format=tidy> (the default) then perltidy will reformat the input file,
and if B<--format=html> then perltidy will produce html output.

For convenience, the abbreviation B<--tidy> is equivalent to B<--format=tidy>,
and B<-html> is equivalent to B<--format=html>.

=item B<--notidy>

This flag disables all formatting and causes the input to be copied unchanged
to the output except for possible changes in line ending characters and any
pre- and post-filters.  This can be useful in conjunction with a hierarchical
set of F<.perltidyrc> files to avoid unwanted code tidying.  See also
L<"Skipping Selected Sections of Code"> for a way to avoid tidying specific
sections of code.

=item B<-i=n>,  B<--indent-columns=n>

Use n columns per indentation level (default n=4).

=item B<-l=n>, B<--maximum-line-length=n>

The default maximum line length is B characters.  Perltidy will try
to find line break points to keep lines below this length. However, long
quotes and side comments may cause lines to exceed this length. And
long lines may sometimes be broken at a length less than B characters
because some of the line break decisions employ small tolerances
to prevent formatting instabilities.

The default length of 80 comes from the past when this was the standard CRT
screen width.  Many programmers prefer to increase this to something like 120.

Setting B<-l=0> is equivalent to setting B<-l=(a very large number)>.  But this is
not recommended because, for example, a very long list will be formatted in a
single long line.

=item B<-vmll>, B<--variable-maximum-line-length>

A problem arises using a fixed maximum line length with very deeply nested code
and data structures because eventually the amount of leading whitespace used
for indicating indentation takes up most or all of the available line width,
leaving little or no space for the actual code or data.  One solution is to use
a very long line length.  Another solution is to use the B<-vmll> flag, which
basically tells perltidy to ignore leading whitespace when measuring the line
length.

To be precise, when the B<-vmll> parameter is set, the maximum line length of a
line of code will be M+L*I, where

      M is the value of --maximum-line-length=M (-l=M), default 80,
      I is the value of --indent-columns=I (-i=I), default 4,
      L is the indentation level of the line of code

When this flag is set, the choice of breakpoints for a block of code should be
essentially independent of its nesting depth.  However, the absolute line
lengths, including leading whitespace, can still be arbitrarily large.  This
problem can be avoided by including the next parameter.

The default is not to do this (B<-nvmll>).

=item B<-wc=n>, B<--whitespace-cycle=n>

This flag also addresses problems with very deeply nested code and data
structures.  When the nesting depth exceeds the value B the leading
whitespace will be reduced and start at a depth of 1 again.  The result is that
blocks of code will shift back to the left rather than moving arbitrarily far
to the right.  This occurs cyclically to any depth.

For example if one level of indentation equals 4 spaces (B<-i=4>, the default),
and one uses B<-wc=15>, then if the leading whitespace on a line exceeds about
4*15=60 spaces it will be reduced back to 4*1=4 spaces and continue increasing
from there.  If the whitespace never exceeds this limit the formatting remains
unchanged.

The combination of B<--variable-maximum-line-length> and
B<--whitespace-cycle=n> provides a solution to the problem of displaying
arbitrarily deep data structures and code in a finite window, although B<--whitespace-cycle=n> may of course be used without B<--variable-maximum-line-length>.

The default is not to use this, which can also be indicated using B<-wc=0>.

=item B

Using tab characters will almost certainly lead to future portability
and maintenance problems, so the default and recommendation is not to
use them.  For those who prefer tabs, however, there are two different
options.

Except for possibly introducing tab indentation characters, as outlined
below, perltidy does not introduce any tab characters into your file,
and it removes any tabs from the code (unless requested not to do so
with B<--freeze-whitespace>).  If you have any tabs in your comments, quotes, or
here-documents, they will remain.

=over 4

=item B<-et=n>,   B<--entab-leading-whitespace>

This flag causes each B leading space characters produced by the
formatting process to be replaced by one tab character.  The
formatting process itself works with space characters. The B<-et=n> parameter is applied
as a last step, after formatting is complete, to convert leading spaces into tabs.
Before starting to use tabs, it is essential to first get the indentation
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>).

The value of the integer B can be any value but can be coordinated with the
number of spaces used for indentation. For example, B<-et=4 -ci=4 -i=4> will
produce one tab for each indentation level and one for each continuation
indentation level.  You may want to coordinate the value of B with what your
display software assumes for the spacing of a tab.

The default is not to use this, which can also be indicated using B<-et=0>.

=item B<-t>,   B<--tabs>

This flag causes one leading tab character to be inserted for each level
of indentation.  Certain other features are incompatible with this
option, and if these options are also given, then a warning message will
be issued and this flag will be unset.  One example is the B<--line-up-parentheses>
option. This flag is retained for backwards compatibility, but
if you use tabs, the B<--entab-leading-whitespace=n> flag is recommended.  If both B<--tabs> and
B<--entab-leading-whitespace=n> are set, then B<--entab-leading-whitespace=n> is used.

=item B<-dt=n>,   B<--default-tabsize=n>

If the first line of code passed to perltidy contains leading tabs but no
tab scheme is specified for the output stream then perltidy must guess how many
spaces correspond to each leading tab.  This number of spaces B
corresponding to each leading tab of the input stream may be specified with
B<-dt=n>.  The default is B.

This flag has no effect if a tab scheme is specified for the output stream,
because then the input stream is assumed to use the same tab scheme and
indentation spaces as for the output stream (any other assumption would lead to
unstable editing).

=back

=item B<-io>,   B<--indent-only>

This flag is used to deactivate all whitespace and line break changes
within non-blank lines of code.
When it is in effect, the only change to the script will be
to the indentation and to the number of blank lines.
And any flags controlling whitespace and newlines will be ignored.  You
might want to use this if you are perfectly happy with your whitespace
and line breaks, and merely want perltidy to handle the indentation.
(This also speeds up perltidy by well over a factor of two, so it might be
useful when perltidy is merely being used to help find a brace error in
a large script).

Setting this flag is equivalent to setting B<--freeze-newlines> and
B<--freeze-whitespace>.

If you also want to keep your existing blank lines exactly
as they are, you can add B<--freeze-blank-lines>.

With this option perltidy is still free to modify the indenting (and
outdenting) of code and comments as it normally would.  If you also want to
prevent long comment lines from being outdented, you can add either B<--nooutdent-long-lines> (B<-noll>) or B<--maximum-line-length=0> (B).

Setting this flag will prevent perltidy from doing any special operations on
closing side comments.  You may still delete all side comments however when
this flag is in effect.

=item B<-enc=s>,  B<--character-encoding=s>

This flag indicates if the input data stream uses a character encoding.
Perltidy does not look for the encoding directives in the source stream, such
as B, and instead relies on this flag to determine the encoding.
(This is because perltidy often works on snippets of code rather than complete
files, so it cannot rely on B directives).  Consequently perltidy is
likely to encounter problems formatting a file which is only partially encoded.

The possible values for B are:

 -enc=none if no encoding is used, or
 -enc=utf8 for encoding in utf8
 -enc=guess if perltidy should guess between these two possibilities.

The value B causes the stream to be processed without special encoding
assumptions.  This is appropriate for files which are written in single-byte
character encodings such as latin-1.

The value B causes the stream to be read and written as
UTF-8.  If the input stream cannot be decoded with this encoding then
processing is not done.

The value B tells perltidy to guess between either utf8 encoding or no
encoding (meaning one character per byte).  The B option uses the
Encode::Guess module which has been found to be reliable at detecting
if a file is encoded in utf8 or not.

The current default is B.

The abbreviations B<-utf8> or B<-UTF8> are equivalent to B<-enc=utf8>, and the
abbreviation B<-guess> is equivalent to B<-enc=guess>.  So to process a file
named B which is encoded in UTF-8 you can use:

   perltidy -utf8 file.pl

or

   perltidy -guess file.pl

or simply

   perltidy file.pl

since B<-guess> is the default.

To process files with an encoding other than UTF-8, it would be necessary to
write a short program which calls the Perl::Tidy module with some pre- and
post-processing to handle decoding and encoding.

=item B<-eos=s>,   B<--encode-output-strings=s>

This flag was added to resolve an issue involving the interface between
Perl::Tidy and calling programs, and in particular B.

If you only run the B binary this flag has no effect.  If you run a
program which calls the Perl::Tidy module and receives a string in return, then
the meaning of the flag is as follows:

=over 4

=item *

The setting B<-eos> means Perl::Tidy should encode any string which it decodes.
This is the default because it makes perltidy behave well as a filter,
and is the correct setting for most programs.

=item *

The setting B<-neos> means that a string should remain decoded if it was
decoded by Perl::Tidy.  This is only appropriate if the calling program will
handle any needed encoding before outputting the string.

=back

The default was changed from B<-neos> to B<-eos> in versions after 20220217.
If this change causes a program to start running incorrectly on encoded files,
an emergency fix might be to set B<-neos>.  Additional information can be found
in the man pages for the B module and also in
L

=item B<-gcs>,  B<--use-unicode-gcstring>

This flag controls whether or not perltidy may use module Unicode::GCString to
obtain accurate display widths of wide characters.  The default
is B<--nouse-unicode-gcstring>.

If this flag is set, and text is encoded, perltidy will look for the module
Unicode::GCString and, if found, will use it to obtain character display
widths.  This can improve displayed vertical alignment for files with wide
characters.  It is a nice feature but it is off by default to avoid conflicting
formatting when there are multiple developers.  Perltidy installation does not
require Unicode::GCString, so users wanting to use this feature need set this
flag and also to install Unicode::GCString separately.

If this flag is set and perltidy does not find module Unicode::GCString,
a warning message will be produced and processing will continue but without
the potential benefit provided by the module.

Also note that actual vertical alignment depends upon the fonts used by the
text display software, so vertical alignment may not be optimal even when
Unicode::GCString is used.

=item B<-ole=s>,  B<--output-line-ending=s>

where s=C, C, C, or C.  This flag tells perltidy
to output line endings for a specific system.  Normally,
perltidy writes files with the line separator character of the host
system.  The C and C flags have an identical result.

=item B<-ple>,  B<--preserve-line-endings>

This flag tells perltidy to write its output files with the same line
endings as the input file, if possible.  It should work for
B, B, and B line endings.  It will only work if perltidy
input comes from a filename (rather than stdin, for example).  If
perltidy has trouble determining the input file line ending, it will
revert to the default behavior of using the line ending of the host system.

=item B<-atnl>,  B<--add-terminal-newline>

This flag, which is enabled by default, allows perltidy to terminate the last
line of the output stream with a newline character, regardless of whether or
not the input stream was terminated with a newline character.  If this flag is
negated, with B<-natnl>, then perltidy will add a terminal newline to the
output stream only if the input stream is terminated with a newline.

Negating this flag may be useful for manipulating one-line scripts intended for
use on a command line.

=item B<-it=n>,   B<--iterations=n>

This flag causes perltidy to do B complete iterations.  The reason for this
flag is that code formatting is an iterative process and in some
cases the output from perltidy can be different if it is applied a second time.
For most purposes the default of B should be satisfactory.  However B
can be useful when a major style change is being made, or when code is being
beautified on check-in to a source code control system.  It has been found to
be extremely rare for the output to change after 2 iterations.  If a value
B is greater than 2 is input then a convergence test will be used to stop
the iterations as soon as possible, almost always after 2 iterations.  See
the next item for a simplified iteration control.

This flag has no effect when perltidy is used to generate html.

=item B<-conv>,   B<--converge>

This flag is equivalent to B<-it=4> and is included to simplify iteration
control.  Perltidy will check for convergence and stop iterating as soon as
possible.  The default is B<-nconv> (no convergence check).  Using B<-conv>
will approximately double run time since typically one extra iteration is
required to verify convergence.  No extra iterations are required if no new
line breaks are made, and two extra iterations are occasionally needed when
reformatting complex code structures, such as deeply nested ternary statements.

=back

=head2 Code Indentation Control

The basic indentation model used by perltidy sets the indentation of a line equal to
the sum of any number of primary indentation levels, each of which corresponds to
the entry into a new container, plus one continuation level, which arises when a
statement is broken across multiple lines. This is not the most general possible
model, but it has been found to work well with most perl code while
also allowing robust coding which avoids instabilities.

The number of spaces corresponding to these primary and secondary (continuation)
levels can be independently controlled. The number of spaces for the
primary indentation is B<--indent-columns=n>, or B<-i=n>, as described above.
The number of spaces for the secondary indentation is described in the next section.

=over 4

=item B<-ci=n>, B<--continuation-indentation=n>

Continuation indentation is extra indentation spaces applied when
a long line is broken.  The default is n=2, illustrated here:

 my $level =   # -ci=2
   ( $max_index_to_go >= 0 ) ? $levels_to_go[0] : $last_output_level;

The same example, with n=0, is a little harder to read:

 my $level =   # -ci=0
 ( $max_index_to_go >= 0 ) ? $levels_to_go[0] : $last_output_level;

The value given to B<-ci> is also used by some commands when a small
space is required.  Examples are commands for outdenting labels,
B<--outdent-labels> (B<-ola>), and control keywords, B<--outdent-keywords> (B<-okw>).

When default values are not used, it is recommended that either

(1) the value B given with B<-ci=n> be no more than about one-half of the
number of spaces assigned to a full indentation level on the B<-i=n> command, or

(2) the flag B<--extended-continuation-indentation> is used (see next section).

=item B<-xci>, B<--extended-continuation-indentation>

This flag allows perltidy to use some improvements which have been made to its
indentation model. One of the things it does is "extend" continuation
indentation deeper into structures, hence the name.  The improved indentation
is particularly noticeable when the flags B<-ci=n> and B<-i=n> use the same value of
B. There are no significant disadvantages to using this flag, but to avoid
disturbing existing formatting the default is not to use it, B<-nxci>.

Please see the section L<"B<-pbp>, B<--perl-best-practices>"> for an example of
how this flag can improve the formatting of ternary statements.  It can also
improve indentation of some multiline qw lists as shown below.

        # perltidy
        foreach $color (
            qw(
            AntiqueWhite3 Bisque1 Bisque2 Bisque3 Bisque4
            SlateBlue3 RoyalBlue1 SteelBlue2 DeepSkyBlue3
            ),
            qw(
            LightBlue1 DarkSlateGray1 Aquamarine2 DarkSeaGreen2
            SeaGreen1 Yellow1 IndianRed1 IndianRed2 Tan1 Tan4
            )
          )

        # perltidy -xci
        foreach $color (
            qw(
                AntiqueWhite3 Bisque1 Bisque2 Bisque3 Bisque4
                SlateBlue3 RoyalBlue1 SteelBlue2 DeepSkyBlue3
            ),
            qw(
                LightBlue1 DarkSlateGray1 Aquamarine2 DarkSeaGreen2
                SeaGreen1 Yellow1 IndianRed1 IndianRed2 Tan1 Tan4
            )
          )

=item B<-mci>, B<--minimize-continuation-indentation>

This flag allows perltidy to remove continuation indentation in some
special cases where it is not really unnecessary. For a simple example,
the default formatting for the following snippet is:

    # perltidy -nmci
    $self->blurt( "Error: No INPUT for type '$type', typekind '"
          . $type->xstype
          . "' found" );

The second and third lines are one level deep in a container, and are also
statement continuations, so they get indented by the sum of the full indentation B<-i>
value and the continuation indentation B<-ci> value.  If this flag is set, the indentation is reduced by
B<-ci> spaces, giving

    # perltidy -mci
    $self->blurt( "Error: No INPUT for type '$type', typekind '"
        . $type->xstype
        . "' found" );

This flag is off by default.

=item B<-sil=n> B<--starting-indentation-level=n>

By default, perltidy examines the input file and tries to determine the
starting indentation level.  While it is often zero, it may not be
zero for a code snippet being sent from an editing session.

To guess the starting indentation level perltidy simply assumes that
indentation scheme used to create the code snippet is the same as is being used
for the current perltidy process.  This is the only sensible guess that can be
made.  It should be correct if this is true, but otherwise it probably won't.
For example, if the input script was written with B<-i=2> and the current perltidy
flags have B<-i=4>, the wrong initial indentation will be guessed for a code
snippet which has non-zero initial indentation. Likewise, if an entabbing
scheme is used in the input script and not in the current process then the
guessed indentation will be wrong.

If the default method does not work correctly, or you want to change the
starting level, use B<-sil=n>, to force the starting level to be n.

=item B using B<--line-up-parentheses>, B<-lp> or B<--extended--line-up-parentheses> , B<-xlp>

These flags provide an alternative indentation method for list data.  The
original flag for this is B<-lp>, but it has some limitations (explained below)
which are avoided with the newer B<-xlp> flag.  So B<-xlp> is probably the better
choice for new work, but the B<-lp> flag is retained to minimize changes to
existing formatting.
If you enter both B<-lp> and B<-xlp>, then B<-xlp> will be used.


In the default indentation method perltidy indents lists with 4 spaces, or
whatever value is specified with B<-i=n>.  Here is a small list formatted in
this way:

    # perltidy (default)
    @month_of_year = (
        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
    );

The B<-lp> or B<-xlp> flags add extra indentation to cause the data to begin
past the opening parentheses of a sub call or list, or opening square bracket
of an anonymous array, or opening curly brace of an anonymous hash.  With this
option, the above list would become:

    # perltidy -lp or -xlp
    @month_of_year = (
                       'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                       'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
    );

If the available line length (see B<-l=n> ) does not permit this much
space, perltidy will use less.   For alternate placement of the
closing paren, see the next section.

These flags have no effect on code BLOCKS, such as if/then/else blocks,
which always use whatever is specified with B<-i=n>.

Some limitations on these flags are:

=over 4

=item *

A limitation on B<-lp>, but not B<-xlp>, occurs in situations where perltidy
does not have complete freedom to choose line breaks. Then it may temporarily revert
to its default indentation method.  This can occur for example if there are
blank lines, block comments, multiline quotes, or side comments between the
opening and closing parens, braces, or brackets.  It will also occur if a
multiline anonymous sub occurs within a container since that will impose
specific line breaks (such as line breaks after statements).

=item *

For both the B<-lp> and B<-xlp> flags, any parameter which significantly
restricts the ability of perltidy to choose newlines will conflict with these
flags and will cause them to be deactivated.  These include B<--indent-only>, B<--freeze-newlines>,
B<--noadd-newlines>, and B<--nodelete-old-newlines>.

=item *

The B<-lp> and B<-xlp> options may not be used together with the B<-t> tabs option.
They may, however, be used with the B<-et=n> tab method

=back

There are some potential disadvantages of this indentation method compared to
the default method that should be noted:

=over 4

=item *

The available line length can quickly be used up if variable names are
long.  This can cause deeply nested code to quickly reach the line length
limit, and become badly formatted, much sooner than would occur with the
default indentation method.

=item *

Since the indentation depends on the lengths of variable names, small
changes in variable names can cause changes in indentation over many lines in a
file.  This means that minor name changes can produce significant file
differences.  This can be annoying and does not occur with the default
indentation method.

=back

Some things that can be done to minimize these problems are:

=over 4

=item *

Increase B<--maximum-line-length=n> above the default B characters if
necessary.

=item *

If you use B<-xlp> then long side comments can limit the indentation over
multiple lines.  Consider adding the flag B<--ignore-side-comment-lengths> to
prevent this, or minimizing the use of side comments.

=item *

Apply this style in a limited way.  By default, it applies to all list
containers (not just lists in parentheses).  The next section describes how to
limit this style to, for example, just function calls.  The default indentation
method will be applied elsewhere.

=back

=item B<-lpil=s>, B<--line-up-parentheses-inclusion-list> and B<-lpxl=s>,  B<--line-up-parentheses-exclusion-list>

The following discussion is written for B<-lp> but applies equally to the newer B<-xlp> version.
By default, the B<-lp> flag applies to as many containers as possible.
The set of containers to which the B<-lp> style applies can be reduced by
either one of these two flags:

Use B<--line-up-parentheses-inclusion-list=s> (B<-lpil=s>) to specify the containers to which B<-lp> applies, or

use B<--line-up-parentheses-exclusion-list=s> (B<-lpxl=s>) to specify the containers to which B<-lp> does NOT apply.

Only one of these two flags may be used.  Both flags can achieve the same
result, but the B<-lpil=s> flag is much easier to describe and use and is
recommended.  The B<-lpxl=s> flag was the original implementation and is
only retained for backwards compatibility.

This list B for these parameters is a string with space-separated items.
Each item consists of up to three pieces of information in this order: (1) an
optional letter code (2) a required container type, and (3) an optional numeric
code.

The only required piece of information is a container type, which is one of
'(', '[', or '{'.  For example the string

  -lpil='('

means use -lp formatting only on lists within parentheses, not lists in square-brackets or braces.
The same thing could alternatively be specified with

  -lpxl = '[ {'

which says to exclude lists within square-brackets and braces.  So what remains is lists within parentheses.

A second optional item of information which can be given for parentheses is an alphanumeric
letter which is used to limit the selection further depending on the type of
token immediately before the paren.  The possible letters are currently 'k',
'K', 'f', 'F', 'w', and 'W', with these meanings for matching whatever precedes an opening paren (see L<"Specifying Paren Types">):

 'k' matches if the previous nonblank token is a perl keyword
     (such as 'if', 'while'),
 'K' matches if 'k' does not: previous token is not a keyword
 'f' matches if previous token is a function (not a keyword)
 'F' matches if 'f' does not.
 'w' matches if either 'k' or 'f' match.
 'W' matches if 'w' does not.

For example:

  -lpil = 'f('

means only apply -lp to function calls, and

  -lpil = 'w('

means only apply -lp to parenthesized lists which follow a function or a keyword.

This last example could alternatively be written using the B<-lpxl=s> flag as

  -lpxl = '[ { W('

which says exclude B<-lp> for lists within square-brackets, braces, and parens NOT preceded by
a keyword or function.   Clearly, the B<-lpil=s> method is easier to understand.

An optional numeric code may follow any of the container types to further refine the selection based
on container contents.  The numeric codes are:

  '0' or blank: no restriction is placed on container contents
  '1' the container contents must be a simple list without sublists
  '2' the container contents must be a simple list without sublists,
      without code blocks, and without ternary operators

For example,

  -lpil = 'f(2'

means only apply -lp to function calls with simple lists (not containing any sublists,
code blocks or ternary expressions).

=item B<-cti=n>, B<--closing-token-indentation>

The B<-cti=n> flag controls the indentation of a line beginning with
a C<)>, C<]>, or a non-block C<}>.  Such a line receives:

 -cti = 0 no extra indentation (default)
 -cti = 1 extra indentation such that the closing token
        aligns with its opening token.
 -cti = 2 one extra indentation level if the line looks like:
        );  or  ];  or  };
 -cti = 3 one extra indentation level always

The flags B<-cti=1> and B<-cti=2> work well with the B<--line-up-parentheses>
(B<-lp>) flag (previous section).

    # perltidy -lp -cti=1
    @month_of_year = (
                       'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                       'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
                     );

    # perltidy -lp -cti=2
    @month_of_year = (
                       'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                       'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
                       );

These flags are merely hints to the formatter and they may not always be
followed.  In particular, if -lp is not being used, the indentation for
B is constrained to be no more than one indentation level.

If desired, this control can be applied independently to each of the
closing container token types.  In fact, B<-cti=n> is merely an
abbreviation for B<-cpi=n -csbi=n -cbi=n>, where:
B<-cpi> or B<--closing-paren-indentation> controls B<)>'s,
B<-csbi> or B<--closing-square-bracket-indentation> controls B<]>'s,
B<-cbi> or B<--closing-brace-indentation> controls non-block B<}>'s.

=item B<-icp>, B<--indent-closing-paren>

The B<-icp> flag is equivalent to
B<-cti=2>, described in the previous section.  The B<-nicp> flag is
equivalent B<-cti=0>.  They are included for backwards compatibility.

=item B<-icb>, B<--indent-closing-brace>

The B<-icb> option gives one extra level of indentation to a brace which
terminates a code block .  For example,

        if ($task) {
            yyy();
            }    # -icb
        else {
            zzz();
            }

The default is not to do this, indicated by B<-nicb>.

=item B<-ils>, B<--indent-leading-semicolon>

A line which begins with a leading semicolon will, by default, have the extra
number of indentation spaces defined by B<--continuation-indentation=n>.
This extra indentation can be removed by setting B<-nils>.

    # default
    $z = sqrt( $x**2 + $y**2 )

      ;    # <-- indented by ci spaces

    # -nils
    $z = sqrt( $x**2 + $y**2 )

    ;    # <-- not indented by ci spaces

Note that leading semicolons do not normally occur unless requested with
B<--break-at-old-semicolon-breakpoints> or forced, for example by
a blank line as in this example.

=item B<-nib>, B<--non-indenting-braces>

Normally, lines of code contained within a pair of block braces receive one
additional level of indentation.  This flag, which is enabled by default,
causes perltidy to look for
opening block braces which are followed by a special side comment. This special
side comment is B<#<<<> by default.  If found, the code between this opening brace and its
corresponding closing brace will not be given the normal extra indentation
level.  For example:

        { #<<<   a closure to contain lexical vars

        my $var;  # this line does not get one level of indentation
        ...

        }

        # this line does not 'see' $var;

This can be useful, for example, when combining code from different files.
Different sections of code can be placed within braces to keep their lexical
variables from being visible to the end of the file.  To keep the new braces
from causing all of their contained code to be indented if you run perltidy,
and possibly introducing new line breaks in long lines, you can mark the
opening braces with this special side comment.

Only the opening brace needs to be marked, since perltidy knows where the
closing brace is.  Braces contained within marked braces may also be marked
as non-indenting.

If your code happens to have some opening braces followed by '#<<<', and you
don't want this behavior, you can use B<-nnib> to deactivate it.  To make it
easy to remember, the default string is the same as the string for starting a
B section. There is no confusion because in that case it is
for a block comment rather than a side-comment.

The special side comment can be changed with the next parameter.


=item B<-nibp=s>, B<--non-indenting-brace-prefix=s>

The B<-nibp=string> parameter may be used to change the marker for
non-indenting braces.  The default is equivalent to -nibp='#<<<'.  The string
that you enter must begin with a # and should be in quotes as necessary to get
past the command shell of your system.  This string is the leading text of a
regex pattern that is constructed by prepending a '^' and appending
a'\s', so you must also include backslashes for characters to be taken
literally rather than as patterns.

For example, to match the side comment '#++', the parameter would be

  -nibp='#\+\+'


=item B<-olq>, B<--outdent-long-quotes>

When B<-olq> is set, lines which is a quoted string longer than the
value B will have their indentation removed to make
them more readable.  This is the default.  To prevent such out-denting,
use B<-nolq>.

=item B<-oll>, B<--outdent-long-lines>

This command is equivalent to the combination B<--outdent-long-quotes> and
B<--outdent-long-comments>, and it is included for compatibility with previous
versions of perltidy.  The negation of this also works, B<-noll> or
B<--nooutdent-long-lines>, and is equivalent to setting B<-nolq> and B<-nolc>.

=item B B<-ola>,  B<--outdent-labels>

This command will cause labels to be outdented by the number of spaces defined
by B<--continuation-indentation=n>, if possible.
This is the default.  For example:

        my $i;
      LOOP: while ( $i =  ) {
            chomp($i);
            next unless $i;
            fixit($i);
        }

Use B<-nola> to prevent this.  To control line breaks after labels see L<"-bal=n, --break-after-labels=n">.

=item B

=over 4

=item B<-okw>,  B<--outdent-keywords>

The command B<-okw> will cause certain leading control keywords to
be outdented by the number of spaces defined by
B<--continuation-indentation=n>spaces, if
possible.  By default, these keywords are C, C, C,
C, and C.  The intention is to make these control keywords
easier to see.  To change this list of keywords being outdented, see
the next section.

For example, using C on the previous example gives:

        my $i;
      LOOP: while ( $i =  ) {
            chomp($i);
          next unless $i;
            fixit($i);
        }

Notice that the keyword B has been outdented. The default is not to do
this.

=item B B<-okwl=string>,  B<--outdent-keyword-list=string>

This command can be used to change the keywords which are outdented with
the B<-okw> command.  The parameter B is a required list of perl
keywords, which should be placed in quotes if there are more than one.
By itself, it does not cause any outdenting to occur, so the B<-okw>
command is still required.

For example, the commands C<-okwl="next last redo goto" -okw> will cause
those four keywords to be outdented.

=back

=back

=head2 Whitespace Control

Whitespace refers to the blank space between variables, operators,
and other code tokens.

=over 4

=item B<-fws>,  B<--freeze-whitespace>

This flag causes your original whitespace to remain unchanged, and
causes the rest of the whitespace commands in this section, the
Code Indentation section, and
the Comment Control section to be ignored.

=item B

Here the term "tightness" will mean the closeness with which
pairs of enclosing tokens, such as parentheses, contain the quantities
within.  A numerical value of 0, 1, or 2 defines the tightness, with
0 being least tight and 2 being most tight.  Spaces within containers
are always symmetric, so if there is a space after a C<(> then there
will be a space before the corresponding C<)>.

The B<-pt=n> or B<--paren-tightness=n> parameter controls the space within
parens.  The example below shows the effect of the three possible
values, 0, 1, and 2:

 if ( ( my $len_tab = length( $tabstr ) ) > 0 ) {  # -pt=0
 if ( ( my $len_tab = length($tabstr) ) > 0 ) {    # -pt=1 (default)
 if ((my $len_tab = length($tabstr)) > 0) {        # -pt=2

When n is 0, there is always a space to the right of a '(' and to the left
of a ')'.  For n=2 there is never a space.  For n=1, the default, there
is a space unless the quantity within the parens is a single token, such
as an identifier or quoted string.

Likewise, the parameter B<-sbt=n> or B<--square-bracket-tightness=n>
controls the space within square brackets, as illustrated below.

 $width = $col[ $j + $k ] - $col[ $j ];  # -sbt=0
 $width = $col[ $j + $k ] - $col[$j];    # -sbt=1 (default)
 $width = $col[$j + $k] - $col[$j];      # -sbt=2

Curly braces which do not contain code blocks are controlled by
the parameter B<-bt=n> or B<--brace-tightness=n>.

 $obj->{ $parsed_sql->{ 'table' }[0] };    # -bt=0
 $obj->{ $parsed_sql->{'table'}[0] };      # -bt=1 (default)
 $obj->{$parsed_sql->{'table'}[0]};        # -bt=2

And finally, curly braces which contain blocks of code are controlled by the
parameter B<-bbt=n> or B<--block-brace-tightness=n> as illustrated in the
example below (B<-bbt=0> is the default).

 %bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # -bbt=0
 %bf = map { $_ => -M $_ } grep {/\.deb$/} dirents '.';   # -bbt=1
 %bf = map {$_ => -M $_} grep {/\.deb$/} dirents '.';     # -bbt=2

To simplify input in the case that all of the tightness flags have the same
value B, the parameter B<-act=n> or B<--all-containers-tightness=n> is an
abbreviation for the combination B<-pt=n -sbt=n -bt=n -bbt=n>.

=item B<-mutt=s>,   B<--multiple-token-tightness=s>

To review, the tightness controls described in the previous section have three
possible integer values: 0, 1, and 2, where B always adds a space, and
B never adds a space.

The default value B adds space only if the container holds multiple
tokens.  Some perltidy tokens may be rather long, and it can be
preferable to space some of them as if they were multiple tokens.  This can be
done with this parameter.

For example, in the following expression the C list is a single token and
therefore there the default formatting does not put spaces within the square
brackets:

    my $rlist = [qw(alpha beta gamma)];

This can be changed with

    # perltidy -mutt='qw'
    my $rlist = [ qw(alpha beta gamma) ];

This tells perltidy to space a Clist as if it were multiple tokens when the
default tightness is used.

The parameter B may contain any of the following perl operators:

    qw q qq qx qr s y tr m

Other possible specifications are

    q*   - all of the above operators
    Q    - all of the above plus any quoted text
    h    - a here-doc target, such as '<> - the double-diamond operator

A symbol may be negated by preceding it with a carat B<^> symbol.
The double-diamond operator is always included unless negated in this way.

=item B<-xbt>,   B<--extended-block-tightness>

There are two controls for spacing within curly braces, namely
B<--block-brace-tightness=n> for code block braces and B<--brace-tightness=n>
for all other braces.

There is a little fuzziness in this division of brace types though because the
curly braces considered by perltidy to contain code blocks for formatting
purposes, such as highlighting code structure, exclude some of the small code
blocks used by Perl mainly for isolating terms.  These include curly braces
following a keyword where an indirect object might occur, or curly braces
following a type symbol.  For example, perltidy does not mark the following
braces as code block braces:

    print {*STDERR} $message;
    return ${$foo};

Consequently, the spacing within these small braced containers by default
follows the flag B<--brace-tightness=n> rather than
B<--block-brace-tightness=n>, as one might expect.

If desired, small blocks such as these can be made to instead follow the
spacing defined by the B<--block-brace-tightness=n> flag by setting
B<--extended-block-tightness>.  The specific types of small blocks to which
this parameter applies is controlled by a companion control parameter,
described in the next section.

Note that if the two flags B<--block-brace-tightness=n> and
B<--brace-tightness=n> have the same value B then there would be no reason
to set this flag.

=item B<-xbtl=s>,   B<--extended-block-tightness-list=s>

The previous parameter B<--extended-block-tightness> (B<-xbt>) can be made to
apply to curly braces preceded by any of the keywords

    print printf exec system say

and/or the special symbols

    $ @ % & * $#

The parameter string B may contain a selection of these keywords and symbols
to indicate the brace types to which B<--extended-block-tightness> applies.
For convenience, all of
the keywords can be selected with 'k', and all of the special symbols
can be selected with 't'.  The default is equivalent to B<-xbtl='k'>, which
selects all of the keywords.

Examples:

  -xbtl='k'          # selects just the keywords [DEFAULT]
  -xbtl="t"          # selects just the special type symbols
  -xbtl="k t"        # selects all keywords and symbols, or simply
  -xbtl="kt"         # selects all keywords and symbols
  -xbtl="print say"  # selects just keywords B and B:

Here are some formatting examples using the default values of
B<--brace-tightness=n> and B<--block-brace-tightness=n>. Note that in these
examples B<$ref> is in block braces but B<$key> is not.

    # default formatting
    print {*STDERR} $message;
    my $val = ${$ref}{$key};

    # perltidy -xbt           or
    # perltidy -xbt -xbtl=k
    print { *STDERR } $message;
    my $val = ${$ref}{$key};

    # perltidy -xbt -xbtl=t
    print {*STDERR} $message;
    my $val = ${ $ref }{$key};

    # perltidy -xbt -xbtl=kt
    print { *STDERR } $message;
    my $val = ${ $ref }{$key};

Finally, note that this parameter merely changes the way that the parameter
B<--extended-block-tightness> works. It has no effect unless
B<--extended-block-tightness> is actually set.

=item B<-tso>,   B<--tight-secret-operators>

The flag B<-tso> causes certain perl token sequences (secret operators)
which might be considered to be a single operator to be formatted "tightly"
(without spaces).  The operators currently modified by this flag are:

     0+  +0  ()x!! ~~<>  ,=>   =( )=

For example the sequence B<0 +>,  which converts a string to a number,
would be formatted without a space: B<0+> when the B<-tso> flag is set.  This
flag is off by default.

=item B<-sts>,   B<--space-terminal-semicolon>

Some programmers prefer a space before all terminal semicolons.  The
default is for no such space, and is indicated with B<-nsts> or
B<--nospace-terminal-semicolon>.

        $i = 1 ;     #  -sts
        $i = 1;      #  -nsts   (default)

=item B<-sfs>,   B<--space-for-semicolon>

Semicolons within B loops may sometimes be hard to see,
particularly when commas are also present.  This option places spaces on
both sides of these special semicolons, and is the default.  Use
B<-nsfs> or B<--nospace-for-semicolon> to deactivate it.

 for ( @a = @$ap, $u = shift @a ; @a ; $u = $v ) {  # -sfs (default)
 for ( @a = @$ap, $u = shift @a; @a; $u = $v ) {    # -nsfs

=item B<-asc>,  B<--add-semicolons>

Setting B<-asc> allows perltidy to add any missing optional semicolon at the end
of a line which is followed by a closing curly brace on the next line.  This
is the default, and may be deactivated with B<-nasc> or B<--noadd-semicolons>.

=item B<-dsm>,  B<--delete-semicolons>

Setting B<-dsm> allows perltidy to delete extra semicolons which are
simply empty statements.  This is the default, and may be deactivated
with B<-ndsm> or B<--nodelete-semicolons>.  (Such semicolons are not
deleted, however, if they would promote a side comment to a block
comment).

=item B<-aws>,  B<--add-whitespace>

Setting this option allows perltidy to add certain whitespace to improve
code readability.  This is the default. If you do not want any
whitespace added, but are willing to have some whitespace deleted, use
B<-naws>.  (Use B<--freeze-whitespace> (B<-fws>) to leave whitespace completely unchanged).

=item B<-dws>,  B<--delete-old-whitespace>

Setting this option allows perltidy to remove optional whitespace between
characters in the input file.  The default is to not to do this
(B<-nodelete-old-whitespace>).  This parameter has little effect by itself.
But in combination with B<--noadd-whitespace> it will cause most of the
whitespace in a file to be removed.

=item B

For those who want more detailed control over the whitespace around
tokens, there are four parameters which can directly modify the default
whitespace rules built into perltidy for any token.  They are:

B<-wls=s> or B<--want-left-space=s>,

B<-nwls=s> or B<--nowant-left-space=s>,

B<-wrs=s> or B<--want-right-space=s>,

B<-nwrs=s> or B<--nowant-right-space=s>.

These parameters are each followed by a quoted string, B, containing a
list of token types.  No more than one of each of these parameters
should be specified, because repeating a command-line parameter
always overwrites the previous one before perltidy ever sees it.

To illustrate how these are used, suppose it is desired that there be no
space on either side of the token types B<= + - / *>.  The following two
parameters would specify this desire:

  -nwls="= + - / *"    -nwrs="= + - / *"

(Note that the token types are in quotes, and that they are separated by
spaces).  With these modified whitespace rules, the following line of math:

  $root = -$b + sqrt( $b * $b - 4. * $a * $c ) / ( 2. * $a );

becomes this:

  $root=-$b+sqrt( $b*$b-4.*$a*$c )/( 2.*$a );

These parameters should be considered to be hints to perltidy rather
than fixed rules, because perltidy must try to resolve conflicts that
arise between them and all of the other rules that it uses.  One
conflict that can arise is if, between two tokens, the left token wants
a space and the right one doesn't.  In this case, the token not wanting
a space takes priority.

It is necessary to have a list of all token types in order to create
this type of input.  Such a list can be obtained by the command
B<--dump-token-types>.  Also try the B<-D> flag on a short snippet of code
and look at the F<.DEBUG> file to see the tokenization.

To illustrate, suppose we do not want a space after a colon which introduces a
sub attribute. We need to know its type. It is not a colon because that is the
type of a ternary operator. The output of B<--dump-token-types> states that it
is token type 'A'.  To verify this, we can run C on a short piece
of code containing such a colon, such as

    sub foo : lvalue;

This produces a F<.DEBUG> file which contains

    1: sub foo : lvalue;
    1: SSSSSSSbAbwwwwww;

The top line is the input, and the bottom line shows the token types.
The 'A' beneath the colon verifies that it is type B.

So to prevent a space on the right of this colon we can use

    # perltidy -nwrs='A'
    sub foo :lvalue;

B Be sure to put these tokens in quotes to avoid having them
misinterpreted by your command shell.

=item B

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:

   sub print_div {
      my ($x,$y)=@_;
      print $x/$y;
   }

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

   sub print_div {
       my ($x,$y)=@_;
       print $x /$y;
   }

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.

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 unknown 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.

In perltidy this is implemented in the tokenizer by marking token following a
B keyword as a special type B.  When formatting is being done,
whitespace following this token type is generally left unchanged as a precaution
against changing program behavior.  This is excessively conservative but simple
and easy to implement.  Keywords which are treated similarly to B include
B, B, B, B.  Changes in spacing around parameters
following these keywords may have to be made manually.  For example, the space,
or lack of space, after the parameter $foo in the following line will be
unchanged in formatting.

   system($foo );
   system($foo);

To find if a token is of type B you can use B. For the
first line above the result is

   1: system($foo );
   1: kkkkkk{ZZZZb};

which shows that B is type B (keyword) and $foo is type B.

=item B

Despite these precautions, it is still possible to introduce syntax errors with
some asymmetric whitespace rules, particularly when call parameters are not
placed in containing parens or braces.  For example, the following two lines will
be parsed by perl without a syntax error:

  # original programming, syntax ok
  my @newkeys = map $_-$nrecs+@data, @oldkeys;

  # perltidy default, syntax ok
  my @newkeys = map $_ - $nrecs + @data, @oldkeys;

But the following will give a syntax error:

  # perltidy -nwrs='-'
  my @newkeys = map $_ -$nrecs + @data, @oldkeys;

For another example, the following two lines will be parsed without syntax error:

  # original programming, syntax ok
  for my $severity ( reverse $LOWEST+1 .. $HIGHEST ) { ...  }

  # perltidy default, syntax ok
  for my $severity ( reverse $LOWEST + 1 .. $HIGHEST ) { ... }

But the following will give a syntax error:

  # perltidy -nwrs='+', syntax error:
  for my $severity ( reverse $LOWEST +1 .. $HIGHEST ) { ... }

To avoid subtle parsing problems like this, it is best to avoid spacing a
binary operator asymmetrically with a space on the left but not on the right.

=item B

When an opening paren follows a Perl keyword, no space is introduced after the
keyword, unless it is (by default) one of these:

   my local our state and or xor err eq ne if else elsif until unless
   while for foreach return switch case given when catch

These defaults can be modified with two commands:

B<-sak=s>  or B<--space-after-keyword=s>  adds keywords.

B<-nsak=s>  or B<--nospace-after-keyword=s>  removes keywords.

where B is a list of keywords (in quotes if necessary).  For example,

  my ( $a, $b, $c ) = @_;    # default
  my( $a, $b, $c ) = @_;     # -nsak="my local our"

The abbreviation B<-nsak='*'> is equivalent to including all of the
keywords in the above list.

When both B<-nsak=s> and B<-sak=s> commands are included, the B<-nsak=s>
command is executed first.  For example, to have space after only the
keywords (my, local, our) you could use B<-nsak="*" -sak="my local our">.

To put a space after all keywords, see the next item.

=item B

When an opening paren follows a function or keyword, no space is introduced
after the keyword except for the keywords noted in the previous item.  To
always put a space between a function or keyword and its opening paren,
use the command:

B<-skp>  or B<--space-keyword-paren>

You may also want to use the flag B<-sfp> (next item) too.

=item B

When an opening paren follows a function the default and recommended formatting
is not to introduce a space.  To cause a space to be introduced use:

B<-sfp>  or B<--space-function-paren>

  myfunc( $a, $b, $c );    # default
  myfunc ( $a, $b, $c );   # -sfp

You will probably also want to use the flag B<-skp> (previous item) too.

The parameter is not recommended because spacing a function paren can make a
program vulnerable to parsing problems by Perl.  For example, the following
two-line program will run as written but will have a syntax error if
reformatted with -sfp:

  if ( -e filename() ) { print "I'm here\n"; }
  sub filename { return $0 }

In this particular case the syntax error can be removed if the line order is
reversed, so that Perl parses 'sub filename' first.

=item B<-fpva>  or B<--function-paren-vertical-alignment>

A side-effect of using the B<-sfp> flag is that the parens may become vertically
aligned. For example,

    # perltidy -sfp
    myfun     ( $aaa, $b, $cc );
    mylongfun ( $a, $b, $c );

This is the default behavior.  To prevent this alignment use B<-nfpva>:

    # perltidy -sfp -nfpva
    myfun ( $aaa, $b, $cc );
    mylongfun ( $a, $b, $c );

=item B<-spp=n>  or B<--space-prototype-paren=n>

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.

      sub usage();

This integer B may have the value 0, 1, or 2 as follows:

    -spp=0 means no space before the paren
    -spp=1 means follow the example of the source code [DEFAULT]
    -spp=2 means always put a space before the paren

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
applying the different options would be:

        sub usage();    # n=0 [no space]
        sub usage();    # n=1 [default; follows input]
        sub usage ();   # n=2 [space]

=item B<-ssp=n>  or B<--space-signature-paren=n>

This flag is analogous to the previous except that it applies to the space before the opening paren of a sub B rather than a sub B.

For example, consider the following line:

      sub circle( $xc, $yc, $rad )

This space before the opening paren can be controlled with integer B which
may have the value 0, 1, or 2 with these meanings:

    -ssp=0 means no space before the paren
    -ssp=1 means follow the example of the source code [DEFAULT]
    -ssp=2 means always put a space before the paren

The default is B<-ssp=1>, meaning that will be a space in the output if, and only if, there is one in the input.  Given the above line of code, the result of
applying the different options would be:

    sub circle( $xc, $yc, $rad )   # n=0 [no space]
    sub circle( $xc, $yc, $rad )   # n=1 [default; same as input]
    sub circle ( $xc, $yc, $rad )  # n=2 [space]

=item B<-kpit=n> or B<--keyword-paren-inner-tightness=n>

The space inside of an opening paren, which itself follows a certain keyword,
can be controlled by this parameter.  The space on the inside of the
corresponding closing paren will be treated in the same (balanced) manner.
This parameter has precedence over any other paren spacing rules.  The values
of B are as follows:

   -kpit=0 means always put a space (not tight)
   -kpit=1 means ignore this parameter [default]
   -kpit=2 means never put a space (tight)

To illustrate, the following snippet is shown formatted in three ways:

    if ( seek( DATA, 0, 0 ) ) { ... }    # perltidy (default)
    if (seek(DATA, 0, 0)) { ... }        # perltidy -pt=2
    if ( seek(DATA, 0, 0) ) { ... }      # perltidy -pt=2 -kpit=0

In the second case the -pt=2 parameter makes all of the parens tight. In the
third case the -kpit=0 flag causes the space within the 'if' parens to have a
space, since 'if' is one of the keywords to which the -kpit flag applies by
default.  The remaining parens are still tight because of the -pt=2 parameter.

The set of keywords to which this parameter applies are by default are:

   if elsif unless while until for foreach

These can be changed with the parameter B<-kpitl=s> described in the next section.


=item B<-kpitl=string> or B<--keyword-paren-inner-tightness-list=string>

This command can be used to change the keywords to which the previous
parameter, B<-kpit=n>,
applies.  The parameter B is a required list either keywords or
functions, which should be placed in quotes if there are more than one.  By
itself, this parameter does not cause any change in spacing, so the B<-kpit=n>
command is still required.

For example, the commands C<-kpitl="if else while" -kpit=2> will cause the just
the spaces inside parens following  'if', 'else', and 'while' keywords to
follow the tightness value indicated by the B<-kpit=2> flag.

=item B<-lop>  or B<--logical-padding>

In the following example some extra space has been inserted on the second
line between the two open parens. This extra space is called "logical padding"
and is intended to help align similar things vertically in some logical
or ternary expressions.

    # perltidy [default formatting]
    $same =
      (      ( $aP eq $bP )
          && ( $aS eq $bS )
          && ( $aT eq $bT )
          && ( $a->{'title'} eq $b->{'title'} )
          && ( $a->{'href'} eq $b->{'href'} ) );

Note that this is considered to be a different operation from "vertical
alignment" because space at just one line is being adjusted, whereas in
"vertical alignment" the spaces at all lines are being adjusted. So it is
sort of a local version of vertical alignment.

Here is an example involving a ternary operator:

    # perltidy [default formatting]
    $bits =
        $top > 0xffff ? 32
      : $top > 0xff   ? 16
      : $top > 1      ? 8
      :                 1;

This behavior is controlled with the flag B<--logical-padding>, which is set
'on' by default.  If it is not desired it can be turned off using
B<--nological-padding> or B<-nlop>.  The above two examples become, with
B<-nlop>:

    # perltidy -nlop
    $same =
      ( ( $aP eq $bP )
          && ( $aS eq $bS )
          && ( $aT eq $bT )
          && ( $a->{'title'} eq $b->{'title'} )
          && ( $a->{'href'} eq $b->{'href'} ) );

    # perltidy -nlop
    $bits =
      $top > 0xffff ? 32
      : $top > 0xff ? 16
      : $top > 1    ? 8
      :               1;


=item B quotes>

B<-tqw> or B<--trim-qw> provide the default behavior of trimming
spaces around multiline C quotes and indenting them appropriately.

B<-ntqw> or B<--notrim-qw> cause leading and trailing whitespace around
multiline C quotes to be left unchanged.  This option will not
normally be necessary, but was added for testing purposes, because in
some versions of perl, trimming C quotes changes the syntax tree.

=item B<-sbq=n>  or B<--space-backslash-quote=n>

lines like

       $str1=\"string1";
       $str2=\'string2';

can confuse syntax highlighters unless a space is included between the backslash and the single or double quotation mark.

this can be controlled with the value of B as follows:

    -sbq=0 means no space between the backslash and quote
    -sbq=1 means follow the example of the source code
    -sbq=2 means always put a space between the backslash and quote

The default is B<-sbq=1>, meaning that a space will be used if there is one in the source code.

=item B

B<-trp> or B<--trim-pod> will remove trailing whitespace from lines of POD.
The default is not to do this.

=back

=head2 Comment Controls

Perltidy has a number of ways to control the appearance of both block comments
and side comments.  The term B here refers to a full-line
comment, whereas B will refer to a comment which appears on a
line to the right of some code.

Perltidy does not do any word wrapping of commented text to match a selected
maximum line length. This is because there is no way to determine if this is
appropriate for the given content. However, an interactive program named
B is available in the B folder of the perltidy
distribution which can assist in doing this.

=over 4

=item B<-ibc>,  B<--indent-block-comments>

Block comments normally look best when they are indented to the same
level as the code which follows them.  This is the default behavior, but
you may use B<-nibc> to keep block comments left-justified.  Here is an
example:

             # this comment is indented      (-ibc, default)
             if ($task) { yyy(); }

The alternative is B<-nibc>:

 # this comment is not indented              (-nibc)
             if ($task) { yyy(); }

See also the next item, B<-isbc>, as well as B<-sbc>, for other ways to
have some indented and some outdented block comments.

=item B<-isbc>,  B<--indent-spaced-block-comments>

If there is no leading space on the line, then the comment will not be
indented, and otherwise it may be.

If both B<-ibc> and B<-isbc> are set, then B<-isbc> takes priority.

=item B<-olc>, B<--outdent-long-comments>

When B<-olc> is set, lines which are full-line (block) comments longer
than the value B will have their indentation
removed.  This is the default; use B<-nolc> to prevent outdenting.

=item B<-msc=n>,  B<--minimum-space-to-comment=n>

Side comments look best when lined up several spaces to the right of
code.  Perltidy will try to keep comments at least n spaces to the
right.  The default is n=4 spaces.

=item B<-fpsc=n>,  B<--fixed-position-side-comment=n>

This parameter tells perltidy to line up side comments in column number B
whenever possible.  The default, n=0, will not do this.

=item B<-iscl>,  B<--ignore-side-comment-lengths>

This parameter causes perltidy to ignore the length of side comments when
setting line breaks.  The default, B<-niscl>, is to include the length of
side comments when breaking lines to stay within the length prescribed
by the B<-l=n> maximum line length parameter.  For example, the following
single line would remain intact with -l=50 and -iscl:

    # perltidy -l=50 -iscl
    $vmsfile =~ s/;[\d\-]*$//;    # Clip off version number

whereas without the -iscl flag the line will be broken:

    # perltidy -l=50
    $vmsfile =~
      s/;[\d\-]*$//;    # Clip off version number

=item B<-ipc>,  B<--ignore-perlcritic-comments>

Perltidy, by default, will look for side comments beginning with
B<## no critic> and ignore their lengths when making line break decisions,
even if the user has not set B<-iscl>.  The reason is that an unwanted line
break can make these special comments ineffective in controlling B.

Setting B<--ignore-perlcritic-comments> tells perltidy not to look for these
B<## no critic> comments.

=item B<-hsc>, B<--hanging-side-comments>

By default, perltidy tries to identify and align "hanging side
comments", which are something like this:

        my $IGNORE = 0;    # This is a side comment
                           # This is a hanging side comment
                           # And so is this

A comment is considered to be a hanging side comment if (1) it immediately
follows a line with a side comment, or another hanging side comment, and
(2) there is some leading whitespace on the line.
To deactivate this feature, use B<-nhsc> or B<--nohanging-side-comments>.
If block comments are preceded by a blank line, or have no leading
whitespace, they will not be mistaken as hanging side comments.

=item B

A closing side comment is a special comment which perltidy can
automatically create and place after the closing brace of a code block.
They can be useful for code maintenance and debugging.  The command
B<-csc> (or B<--closing-side-comments>) adds or updates closing side
comments.  For example, here is a small code snippet

        sub message {
            if ( !defined( $_[0] ) ) {
                print("Hello, World\n");
            }
            else {
                print( $_[0], "\n" );
            }
        }

And here is the result of processing with C:

        sub message {
            if ( !defined( $_[0] ) ) {
                print("Hello, World\n");
            }
            else {
                print( $_[0], "\n" );
            }
        } ## end sub message

A closing side comment was added for C in this case, but not
for the C and C blocks, because they were below the 6 line
cutoff limit for adding closing side comments.  This limit may be
changed with the B<-csci> command, described below.

The command B<-dcsc> (or B<--delete-closing-side-comments>) reverses this
process and removes these comments.

Several commands are available to modify the behavior of these two basic
commands, B<-csc> and B<-dcsc>:

=over 4

=item B<-csci=n>, or B<--closing-side-comment-interval=n>

where C is the minimum number of lines that a block must have in
order for a closing side comment to be added.  The default value is
C.  To illustrate:

        # perltidy -csci=2 -csc
        sub message {
            if ( !defined( $_[0] ) ) {
                print("Hello, World\n");
            } ## end if ( !defined( $_[0] ))
            else {
                print( $_[0], "\n" );
            } ## end else [ if ( !defined( $_[0] ))
        } ## end sub message

Now the C and C blocks are commented.  However, now this has
become very cluttered.

=item B<-cscp=string>, or B<--closing-side-comment-prefix=string>

where string is the prefix used before the name of the block type.  The
default prefix, shown above, is C<## end>.  This string will be added to
closing side comments, and it will also be used to recognize them in
order to update, delete, and format them.  Any comment identified as a
closing side comment will be placed just a single space to the right of
its closing brace.

=item B<-cscl=string>, or B<--closing-side-comment-list>

where C is a list of block types to be tagged with closing side
comments.  By default, all code block types preceded by a keyword or
label (such as C, C, and so on) will be tagged.  The B<-cscl>
command changes the default list to be any selected block types; see
L<"Specifying Block Types">.
For example, the following command
requests that only C's, labels, C, and C blocks be affected by
operations which add (B<-csc>) or delete (B<-dcsc>) closing side comments:

   --closing-side-comment-list='sub : BEGIN END'

=item B<-cscxl=string>, or B<--closing-side-comment-exclusion-list>

where C is a list of block types which should NOT be tagged with
closing side comments. If a block type appears in both B<-cscl> and
B<-cscxl>, then B<-cscxl> has priority and the block will not be tagged.

For example, the following command requests that anonymous subs
should not be affected by any B<-csc> or B<-dcsc> operation:

   --closing-side-comment-exclusion-list='asub'

By default, no block types are excluded.

=item B<-csct=n>, or B<--closing-side-comment-maximum-text=n>

The text appended to certain block types, such as an C block, is
whatever lies between the keyword introducing the block, such as C,
and the opening brace.  Since this might be too much text for a side
comment, there needs to be a limit, and that is the purpose of this
parameter.  The default value is C, meaning that no additional
tokens will be appended to this text after its length reaches 20
characters.  Omitted text is indicated with C<...>.  (Tokens, including
sub names, are never truncated, however, so actual lengths may exceed
this).  To illustrate, in the above example, the appended text of the
first block is C< ( !defined( $_[0] )...>.  The existing limit of
C caused this text to be truncated, as indicated by the C<...>.  See
the next flag for additional control of the abbreviated text.

=item B<-cscb>, or B<--closing-side-comments-balanced>

As discussed in the previous item, when the
closing-side-comment-maximum-text limit is exceeded the comment text must
be truncated.  Older versions of perltidy terminated with three dots, and this
can still be achieved with -ncscb:

  perltidy -csc -ncscb
  } ## end foreach my $foo (sort { $b cmp $a ...

However this causes a problem with editors which cannot recognize
comments or are not configured to do so because they cannot "bounce" around in
the text correctly.  The B<-cscb> flag has been added to
help them by appending appropriate balancing structure:

  perltidy -csc -cscb
  } ## end foreach my $foo (sort { $b cmp $a ... })

The default is B<-cscb>.

=item B<-csce=n>, or B<--closing-side-comment-else-flag=n>

The default, B, places the text of the opening C statement after any
terminal C.

If B is used, then each C is also given the text of the opening
C statement.  Also, an C will include the text of a preceding
C statement.  Note that this may result some long closing
side comments.

If B is used, the results will be the same as B whenever the
resulting line length is less than the maximum allowed.

=item B<-cscb>, or B<--closing-side-comments-balanced>

When using closing-side-comments, and the closing-side-comment-maximum-text
limit is exceeded, then the comment text must be abbreviated.
It is terminated with three dots if the B<-cscb> flag is negated:

  perltidy -csc -ncscb
  } ## end foreach my $foo (sort { $b cmp $a ...

This causes a problem with older editors which do not recognize comments
because they cannot "bounce" around in the text correctly.  The B<-cscb>
flag tries to help them by appending appropriate terminal balancing structures:

  perltidy -csc -cscb
  } ## end foreach my $foo (sort { $b cmp $a ... })

The default is B<-cscb>.


=item B<-cscw>, or B<--closing-side-comment-warnings>

This parameter is intended to help make the initial transition to the use of
closing side comments.
It causes two
things to happen if a closing side comment replaces an existing, different
closing side comment:  first, an error message will be issued, and second, the
original side comment will be placed alone on a new specially marked comment
line for later attention.

The intent is to avoid clobbering existing hand-written side comments
which happen to match the pattern of closing side comments. This flag
should only be needed on the first run with B<-csc>.

=back

B

=over 4

=item *

Closing side comments are only placed on lines terminated with a closing
brace.  Certain closing styles, such as the use of cuddled elses
(B<-ce>), preclude the generation of some closing side comments.

=item *

Please note that adding or deleting of closing side comments takes
place only through the commands B<-csc> or B<-dcsc>.  The other commands,
if used, merely modify the behavior of these two commands.

=item *

It is recommended that the B<-cscw> flag be used along with B<-csc> on
the first use of perltidy on a given file.  This will prevent loss of
any existing side comment data which happens to have the csc prefix.

=item *

Once you use B<-csc>, you should continue to use it so that any
closing side comments remain correct as code changes.  Otherwise, these
comments will become incorrect as the code is updated.

=item *

If you edit the closing side comments generated by perltidy, you must also
change the prefix to be different from the closing side comment prefix.
Otherwise, your edits will be lost when you rerun perltidy with B<-csc>.   For
example, you could simply change C<## end> to be C<## End>, since the test is
case sensitive.  You may also want to use the B<-ssc> flag to keep these
modified closing side comments spaced the same as actual closing side comments.

=item *

Temporarily generating closing side comments is a useful technique for
exploring and/or debugging a perl script, especially one written by someone
else.  You can always remove them with B<-dcsc>.

=back

=item B

Static block comments are block comments with a special leading pattern,
C<##> by default, which will be treated slightly differently from other
block comments.  They effectively behave as if they had glue along their
left and top edges, because they stick to the left edge and previous line
when there is no blank spaces in those places.  This option is
particularly useful for controlling how commented code is displayed.

=over 4

=item B<-sbc>, B<--static-block-comments>

When B<-sbc> is used, a block comment with a special leading pattern, C<##> by
default, will be treated specially.

Comments so identified  are treated as follows:

=over 4

=item *

If there is no leading space on the line, then the comment will not
be indented, and otherwise it may be,

=item *

no new blank line will be
inserted before such a comment, and

=item *

such a comment will never become
a hanging side comment.

=back

For example, assuming C<@month_of_year> is left-adjusted, the default
formatting for the following snippet is:

    # perltidy -sbc [default]
    @month_of_year = (
        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
    ##  'Jul', 'Aug', 'Sep', 'Oct', 'Dec', 'Nov'
        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
    );

This can be useful for displaying code which has been commented out.
Without this convention, the above code would become

    # perltidy -nsbc
    @month_of_year = (
        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',

        ##  'Jul', 'Aug', 'Sep', 'Oct', 'Dec', 'Nov'
        'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
    );

which is less clear.
The default is to use B<-sbc>.  This may be deactivated with B<-nsbc>.

=item B<-sbcp=string>, B<--static-block-comment-prefix=string>

This parameter defines the prefix used to identify static block comments
when the B<-sbc> parameter is set.  The default prefix is C<##>,
corresponding to C<-sbcp=##>.  The prefix is actually part of a perl
pattern used to match lines and it must either begin with C<#> or C<^#>.
In the first case a prefix ^\s* will be added to match any leading
whitespace, while in the second case the pattern will match only
comments with no leading whitespace.  For example, to
identify all comments as static block comments, one would use C<-sbcp=#>.
To identify all left-adjusted comments as static block comments, use C<-sbcp='^#'>.

Please note that B<-sbcp> merely defines the pattern used to identify static
block comments; it will not be used unless the switch B<-sbc> is set.  Also,
please be aware that since this string is used in a perl regular expression
which identifies these comments, it must enable a valid regular expression to
be formed.

A pattern which can be useful is:

    -sbcp=^#{2,}[^\s#]

This pattern requires a static block comment to have at least one character
which is neither a # nor a space.  It allows a line containing only '#'
characters to be rejected as a static block comment.  Such lines are often used
at the start and end of header information in subroutines and should not be
separated from the intervening comments, which typically begin with just a
single '#'.

=item B<-osbc>, B<--outdent-static-block-comments>

The command B<-osbc> will cause static block comments to be outdented by
the number of B<--continuation-spaces=n>, if possible.

=back

=item B

Static side comments are side comments with a special leading pattern.
This option can be useful for controlling how commented code is displayed
when it is a side comment.

=over 4

=item B<-ssc>, B<--static-side-comments>

When B<-ssc> is used, a side comment with a static leading pattern, which is
C<##> by default, will be spaced only a single space from previous
character, and it will not be vertically aligned with other side comments.

The default is B<-nssc>.

=item B<-sscp=string>, B<--static-side-comment-prefix=string>

This parameter defines the prefix used to identify static side comments
when the B<-ssc> parameter is set.  The default prefix is C<##>,
corresponding to C<-sscp=##>.

Please note that B<-sscp> merely defines the pattern used to identify
static side comments; it will not be used unless the switch B<-ssc> is
set.  Also, note that this string is used in a perl regular expression
which identifies these comments, so it must enable a valid regular
expression to be formed.

=back

=back

=head2 Skipping Selected Sections of Code

Selected lines of code may be passed verbatim to the output without any
formatting by marking the starting and ending lines with special comments.
There are two options for doing this.  The first option is called
B<--format-skipping> or B<-fs>, and the second option is called
B<--code-skipping> or B<-cs>.

In both cases the lines of code will be output without any changes.
The difference is that in B<--format-skipping>
perltidy will still parse the marked lines of code and check for errors,
whereas in B<--code-skipping> perltidy will simply pass the lines to the output without any checking.

Both of these features are enabled by default and are invoked with special
comment markers.  B<--format-skipping> uses starting and ending markers '#<<<'
and '#>>>', like this:

 #<<<  format skipping: do not let perltidy change my nice formatting
    my @list = (1,
                1, 1,
                1, 2, 1,
                1, 3, 3, 1,
                1, 4, 6, 4, 1,);
 #>>>

B<--code-skipping> uses starting and ending markers '#<>V', like
this:

 #< | _ |  ] 
        |   <''>
        ]
    };

 #>>V

(The last character V is like a < or > rotated 90 degrees).
Additional text may appear on the special comment lines provided that it is
separated from the marker by at least one space to highlight the sign, as in
the above examples.

Any number of code-skipping or format-skipping sections may appear in a file.
If an opening code-skipping or format-skipping comment is not followed by a
corresponding closing comment, then skipping continues to the end of the file.
If a closing code-skipping or format-skipping comment appears in a file but
does not follow a corresponding opening comment, then it is treated as an
ordinary comment without any special meaning.

It is recommended to use B<--code-skipping> only if you need to hide a block of
an extended syntax which would produce errors if parsed by perltidy, and use
B<--format-skipping> otherwise.  This is because the B<--format-skipping>
option provides the benefits of error checking, and there are essentially no
limitations on which lines to which it can be applied.  The B<--code-skipping>
option, on the other hand, does not do error checking and its use is more
restrictive because the code which remains, after skipping the marked lines,
must be syntactically correct code with balanced containers.

These features should be used sparingly to avoid littering code with markers,
but they can be helpful for working around occasional problems.

Note that it may be possible to avoid the use of B<--format-skipping> for the
specific case of a comma-separated list of values, as in the above example, by
simply inserting a blank or comment somewhere between the opening and closing
parens.  See the section L<"Controlling List Formatting">.

The following sections describe the available controls for these options.  They
should not normally be needed.

=over 4

=item B<-fs>,  B<--format-skipping>

As explained above, this flag, which is enabled by default, causes any code
between special beginning and ending comment markers to be passed to the output
without formatting.  The code between the comments is still checked for errors
however.  The default beginning marker is #<<< and the default ending marker is
#>>>.

Format skipping begins when a format skipping beginning comment is seen and
continues until a format-skipping ending comment is found.

This feature can be disabled with B<-nfs>.   This should not normally be necessary.

=item B<-fsb=string>,  B<--format-skipping-begin=string>

This and the next parameter allow the special beginning and ending comments to
be changed.  However, it is recommended that they only be changed if there is a
conflict between the default values and some other use.  If they are used, it
is recommended that they only be entered in a B<.perltidyrc> file, rather than
on a command line.  This is because properly escaping these parameters on a
command line can be difficult.

If changed comment markers do not appear to be working, use the B<-log> flag and
examine the F<.LOG> file to see if and where they are being detected.

The B<-fsb=string> parameter may be used to change the beginning marker for
format skipping.  The default is equivalent to -fsb='#<<<'.  The string that
you enter must begin with a # and should be in quotes as necessary to get past
the command shell of your system.  It is actually the leading text of a pattern
that is constructed by appending a '\s', so you must also include backslashes
for characters to be taken literally rather than as patterns.

Some examples show how example strings become patterns:

 -fsb='#\{\{\{' becomes /^#\{\{\{\s/ which matches #{{{ but not #{{{{
 -fsb='#\*\*'   becomes /^#\*\*\s/   which matches #** but not #***
 -fsb='#\*{2,}' becomes /^#\*{2,}\s/ which matches #** and #*****

=item B<-fse=string>,  B<--format-skipping-end=string>

The B<-fse=string> is the corresponding parameter used to change the
ending marker for format skipping.  The default is equivalent to
-fse='#<<<'.

The beginning and ending strings may be the same, but it is preferable
to make them different for clarity.

=item B<-cs>,  B<--code-skipping>

As explained above, this flag, which is enabled by default, causes any code
between special beginning and ending comment markers to be directly passed to
the output without any error checking or formatting.  Essentially, perltidy
treats it as if it were a block of arbitrary text.  The default beginning
marker is #<>V.

This feature can be disabled with B<-ncs>.   This should not normally be
necessary.

=item B<-csb=string>,  B<--code-skipping-begin=string>

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>.
The default is equivalent to -csb='#<,  B<--code-skipping-end=string>

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>.
The default is equivalent to -cse='#>>V'.

=back

=head2 Formatting Only Tagged Sections of Code

A command B<--skip-formatting-except-id=tag>, or B<-sfei=tag>, is available to
cause perltidy to B format sections of code which are labeled with the
selected tag on C comments.

For example, the tagged sections might contain tables which are best formatted
with special values of the C<--maximum-line-length> parameter.

The tag name is introduced with the added text B after one or more
spaces on the opening format-skipping comment. The tag B can be any
combination of letters and numbers. For example

 #<<< id=Table27
   ...
 #>>>

The code in this section will be treated like any other format skipping section
unless the parameter B<--skip-formatting-except-id=Table27> is entered.
In that case, it will be formatted.

Here are some points regarding this option:

=over 4

=item *

The special option B<--skip-formatting-except-id='-'>, or B<-sfei='-'>, means
skip all formatting (since a tag named '-' does not exist).  This will allow
the code to be scanned for problems, but the formatting will not be changed.
The B<-notidy> parameter can also be used to skip formatting, but it exits at
an earlier point in the process, so it runs faster but does not perform as many
code checks.

=item *

The sections which are being skipped or formatted can be determined by
dumping a log file with the B<-g> parameter.

=item *

When this option is used, the starting indentation is still guessed from
the first code in the file, even if it is not being formatted.  If this
results in an unwanted indentation of the tagged section, then the
parameter B<--starting-indentation-level=n>, or B<-sil=n>, can be used
to set the desired indentation.

=item *

This feature was suggested in issue git #183 at
L, which discusses an example.

=back

=head2 Formatting a Limited Range of Lines

A command B<--line-range-tidy=n1:n2> is available to process just a selected
range of lines of an input stream with perltidy.  This command is mainly of
interest for programming interactive code editors.  When it is used, the entire
input stream is read but just the selected range of lines of the input file are
processed by the perltidy tokenizer and formatter, and then the stream is
reassembled for output. The selected lines need to contain a complete statement
or balanced container.  Otherwise, a syntax error will occur and the code will
not be tidied.  There are a couple of limitations on the use of this command:
(1) it may not be applied to multiple files, and (2) it only applies to code
tidying and not, for example, html formatting.

=over 4

=item B<-lrt=n1:n2>,  B<--line-range-tidy=n1:n2>

The range of lines is specified by integers B and B, where B is the first line number to be formatted (start counting with 1) and B is the last line number to be formatted.  If B is not given, or exceeds the actual number of lines, then formatting continues to the end of the file.

Examples:

 --line-range-tidy=43:109      # tidy lines 43 through 109
 --line-range-tidy=' 43 : 109' # tidy lines 43 through 109
 --line-range-tidy=1:          # tidy all lines
 --line-range-tidy=0:90        # ERROR (n1 must be >= 1)

The second example shows that spaces are okay if placed in quotes.

=back

=head2 Line Break Control

The parameters in this and the next sections control breaks after
non-blank lines of code.  Blank lines are controlled
separately by parameters in the section L<"Blank Line Control">.

=over 4

=item B<-dnl>,  B<--delete-old-newlines>

By default, perltidy first deletes all old line break locations, and then it
looks for good break points to match the desired line length.  Use B<-ndnl>
or  B<--nodelete-old-newlines> to force perltidy to retain all old line break
points.

=item B<-anl>,  B<--add-newlines>

By default, perltidy will add line breaks when necessary to create
continuations of long lines and to improve the script appearance.  Use
B<-nanl> or B<--noadd-newlines> to prevent any new line breaks.

This flag does not prevent perltidy from eliminating existing line
breaks; see B<--freeze-newlines> to completely prevent changes to line
break points.

=item B<-fnl>,  B<--freeze-newlines>

If you do not want any changes to the line breaks within
lines of code in your script, set
B<-fnl>, and they will remain fixed, and the rest of the commands in
this section and sections
L<"Controlling List Formatting">,
L<"Retaining or Ignoring Existing Line Breaks">.
You may want to use B<--nooutdent-long-lines> with this.

Note: If you also want to keep your blank lines exactly
as they are, you can use the B<--freeze-blank-lines> flag which is described
in the section L<"Blank Line Control">.

=back

=head2 Controlling Breaks at Braces, Parens, and Square Brackets

=over 4

=item B<-ce>,   B<--cuddled-else>

Enable the "cuddled else" style, in which C and C are
follow immediately after the curly brace closing the previous block.
The default is not to use cuddled elses, and is indicated with the flag
B<-nce> or B<--nocuddled-else>.  Here is a comparison of the
alternatives:

  # -ce
  if ($task) {
      yyy();
  } else {
      zzz();
  }

  # -nce (default)
  if ($task) {
      yyy();
  }
  else {
      zzz();
  }

In this example the keyword B is placed on the same line which begins with
the preceding closing block brace and is followed by its own opening block brace
on the same line.  Other keywords and function names which are formatted with
this "cuddled" style are B, B, B, B.

Other block types can be formatted by specifying their names on a
separate parameter B<--cuddled-block-list>, described in a later section.

Cuddling between a pair of code blocks requires that the closing brace of the
first block start a new line.  If this block is entirely on one line in the
input file, it is necessary to decide if it should be broken to allow cuddling.
This decision is controlled by the flag B<--cuddled-break-options=n>
(B<-cbo=n>) discussed below.  The default
and recommended value of B<-cbo=1> bases this decision on the first block in
the chain.  If it spans multiple lines then cuddling is made and continues
along the chain, regardless of the sizes of subsequent blocks. Otherwise, short
lines remain intact.

So for example, the B<--cuddled-else> flag would not have any effect if the
above snippet is rewritten as

  if ($task) { yyy() }
  else {    zzz() }

If the first block spans multiple lines, then cuddling can be done and will
continue for the subsequent blocks in the chain, as illustrated in the previous
snippet.

If there are blank lines between cuddled blocks they will be eliminated.  If
there are comments after the closing brace where cuddling would occur then
cuddling will be prevented.  If this occurs, cuddling will restart later in the
chain if possible.

=item B<-cb>,   B<--cuddled-blocks>

This flag is equivalent to B<--cuddled-else> (B<-ce>).


=item B<-cbl>,    B<--cuddled-block-list>

The built-in default cuddled block types are B.

Additional block types to which the B<--cuddled-blocks> style applies can be defined by
this parameter.  This parameter is a character string, giving a list of
block types separated by commas or spaces.  For example, to cuddle code blocks
of type sort, map and grep, in addition to the default types, the string could
be set to

  -cbl="sort map grep"

or equivalently

  -cbl=sort,map,grep

Note however that these particular block types are typically short so there might not be much
opportunity for the cuddled format style.

Using commas avoids the need to protect spaces with quotes.

As a diagnostic check, the flag B<--dump-cuddled-block-list> or B<-dcbl> can be
used to view the hash of values that are generated by this flag.

Finally, note that the B<--cuddled-block-list> parameter by itself merely
specifies which blocks are formatted with the cuddled format. It has no effect
unless this formatting style is activated with B<--cuddled-else>.

=item B<-cblx>,    B<--cuddled-block-list-exclusive>

When cuddled else formatting is selected with B<--cuddled-else>, setting this
flag causes perltidy to ignore its built-in defaults and rely exclusively on
the block types specified on the B<--cuddled-block-list> flag described in the
previous section.  For example, to avoid using cuddled B and B,
which are among the defaults, the following set of parameters could be used:

  perltidy -ce -cbl='else elsif continue' -cblx

=item B<-cbo=n>, B<--cuddled-break-option=n>

Cuddled formatting is only possible between a pair of code blocks if the
closing brace of the first block starts a new line. If a block is encountered
which is entirely on a single line, and cuddled formatting is selected, it is
necessary to make a decision as to whether or not to "break" the block, meaning
to cause it to span multiple lines.  This parameter controls that decision. The
options are:

   cbo=0  Never force a short block to break.
   cbo=1  If the first of a pair of blocks is broken in the input
          file, then break the second [DEFAULT].
   cbo=2  Break open all blocks for maximal cuddled formatting.

The default and recommended value is B.  With this value, if the starting
block of a chain spans multiple lines, then a cascade of breaks will occur for
remaining blocks causing the entire chain to be cuddled.

The option B can produce erratic cuddling if there are numerous one-line
blocks.

The option B produces maximal cuddling but will not allow any short blocks.

=item B<-bl>, B<--opening-brace-on-new-line>, or B<--brace-left>

Use the flag B<-bl> to place an opening block brace on a new line:

  if ( $input_file eq '-' )
  {
      ...
  }

By default it applies to all structural blocks except B and
anonymous subs.

The default is B<-nbl> which places an opening brace on the same line as
the keyword introducing it if possible.  For example,

  # default
  if ( $input_file eq '-' ) {
     ...
  }

When B<-bl> is set, the blocks to which this applies can be controlled with the
parameters B<--brace-left-list> and B<--brace-left-exclusion-list> described in the next sections.

=item B<-bll=s>, B<--brace-left-list=s>

Use this parameter to change the types of block braces for which the
B<-bl> flag applies; see L<"Specifying Block Types">.  For example,
B<-bll='if elsif else sub'> would apply it to only C
and named sub blocks.  The default is all blocks, B<-bll='*'>.

=item B<-blxl=s>, B<--brace-left-exclusion-list=s>

Use this parameter to exclude types of block braces for which the
B<-bl> flag applies; see L<"Specifying Block Types">.  For example,
the default settings B<-bll='*'> and B<-blxl='sort map grep eval asub'>
mean all blocks except B and anonymous sub blocks.

Note that the lists B<-bll=s> and B<-blxl=s> control the behavior of the
B<-bl> flag but have no effect unless the B<-bl> flag is set. These
two lists provide complete control for this flag, but two shortcut
flags are available and described in the next sections.

=item B<-sbl>,    B<--opening-sub-brace-on-new-line>

The flag B<-sbl> provides a shortcut way to turn on B<-bl> just for named subs.
The same effect can be achieved by turning on B<-bl> with the block list set as
B<-bll='sub'>.  To avoid conflicts, it is recommended to either use the more
general list method described above to control B<-bl>, or this shortcut method,
but not both.

For example,

 perltidy -sbl

produces this result:

 sub message
 {
    if (!defined($_[0])) {
        print("Hello, World\n");
    }
    else {
        print($_[0], "\n");
    }
 }

This negative version of this flag, B<-nsbl>, turns off B<-bl> for
named subs.  The same effect can be achieved with the exclusion
list method, B<-blxl=sub>.

=item B<-asbl>,    B<--opening-anonymous-sub-brace-on-new-line>

The flag B<-asbl> is like the B<-sbl> flag except that it applies to anonymous
sub's instead of named subs.  The same effect can be achieved by turning on
B<-bl> with the block list set to include B<-bll='asub'>.

For example

 perltidy -asbl

produces this result:

 $a = sub
 {
     if ( !defined( $_[0] ) ) {
         print("Hello, World\n");
     }
     else {
         print( $_[0], "\n" );
     }
 };

This negative version of this flag, B<-nasbl>, turns off B<-bl> for
anonymous subs.

=item B<-bli>,    B<--brace-left-and-indent>

The flag B<-bli> is similar to the B<-bl> flag but in addition it causes one
unit of continuation indentation ( see B<--continuation-indentation> ) to be
placed before an opening and closing block braces.

For example

        # perltidy -bli
        if ( $input_file eq '-' )
          {
            important_function();
          }

By default, this extra indentation occurs for block types:
B, B, B, B, B, B, B, B, and
also B and blocks preceded by a B

, B, and B as follows: =over 4 =item B These are variables which are re-declared in the scope of a variable with the identical name. This can be confusing, perhaps not when the code is first written, but possibly later during maintenance work. For example, this can make it difficult to locate the correct variable with an editor when changes are being made. This issue can be avoided by renaming one of the conflicting variables. Note that this is similar to the B policy B. =item B These are variables which have the same bareword name but a different sigil (B<$>, B<@>, or B<%>) as another variable in the same scope. For example, this occurs if variables B<$data> and B<%data> share the same scope. This can also be confusing for the reasons mentioned above and can be avoided by renaming one of the variables. =item B These are lexical variables which are declared in one package and still visible in subroutines of a different package in the same file. This can be confusing, and it might cause the program to run differently, or fail, if the packages were ever split into separate files. This issue can usually be avoided by placing code in block braces of some type. For example, this issue is often found in test code and can sometimes be fixed by using the structure main(); sub main { #<<< ## old main code goes here } The B side comment C<#<<<> is not required but will keep the indentation of the old code unchanged. This check is only applied to package statements which are not enclosed in block braces in order avoid warnings at temporary package changes. =item B These are lexical variables declared with C or C (but not C) and not referenced again within their scope. Calling them B is convenient but not really accurate; this is a "gray area" for a program. There are some good reasons for having such variables. For example, they might occur in a list of values provided by another routine or data structure, and therefore must be listed, even though they might not be referenced again. Having such variables can make them immediately available for future development and debugging, and can be beneficial for program clarity. B sometimes they can occur due to being orphaned by a coding change, due to a misspelling, or by having an unintentional preceding C. So it is worth reviewing them, especially for new code. Here is an example of an unused variable in a script located with this method: BEGIN { my $string = "" } ... $string .= "ok"; This looks nice at first glance, but the scope of the C declaration is limited to the surrounding braces, so it is not the same variable as the other C<$string> and must therefore be reported as unused. This particular problem would have also been caught by perl if the author had used C. =item B These are names which are declared with a C and a reference was not seen again within their package. They might be needed by an external package, or a set of standard definitions, or available for future development. And in some unusual cases a reference may have been missed by perltidy. But they might also be unused remnants from code development, or due to a misspelling, so it can be worthwhile reviewing them. =back B: The following B variables are exempt from warnings: B<$VERSION>, B<@EXPORT>, B<@EXPORT_OK>, B<%EXPORT_TAGS>, B<@ISA, $AUTOLOAD>. =item B The flag B<--warn-variable-types=string>, or B<-wvt=string>, is the B<--warn> counterpart to B<--dump-unusual-variables>, and can be used to produce a warning message if certain of the above variable types are encountered during formatting. All possible variable warnings may be requested with B<-wvt='*'> or B<-wvt=1>. For example, perltidy -wvt='*' somefile.pl The default is not to do any of these checks, and it can also be indicated with B<-wvt=0>. To restrict the check to a specific set warnings, set the input B to be a space-separated or comma-separated list of the letters associated with the types of variables to be checked. For example: perltidy -wvt='s r' somefile.pl will process F normally but issue a warning if either of the issues B or B, described above, are encountered. A companion flag, B<--warn-variable-exclusion-list=string>, or B<-wvxl=string>, can be used to skip warning checks for a list of variable names. A leading and/or trailing '*' may be placed on any of these variable names to allow a partial match. For example, perltidy -wvt=1 -wvxl='$self $class *_unused' somefile.pl will do all possible checks but not report any warnings for variables C<$self>, C<$class>, and for example C<$value_unused>. This partial match option provides a way to trigger a warning message when a new unused variable is detected in a script. This can be accomplished by adding a unique suffix to the names of existing unused variables, such as C<_unused>. This suffix is then added to the exclusion list. As a specific example, consider the following line which is part of some debug code which only references the latter three variables (but might someday need to reference the package variable too). my ( $package_uu, $filename, $line, $subroutine ) = caller(); The unused variable, C<$package_uu>, has been specially marked with suffix C<_uu>. No type B (unused variable) warning will be produced provided that this wildcard suffix is in the exclusion list: -wvxl='*_uu' =item B to help locate misspelled hash keys The parameter B<--dump-unique-keys>, or B<-duk>, dumps a list of hash keys which appear to be used just once, and do not appear among the quoted strings in a file. For example: perltidy -duk File.pm >output.txt The lines in the output file list unique keys and line numbers. Many programs contain sets of hash keys which are largely unique to that program but which are used for communication with other programs. A filter is used to avoid listing such keys. This filter is described in the next section. A program C at L can run perltidy with B<-duk> on multiple files, and then remove any common keys from the list. =item B, or B<-wukc=N>, to adjust the unique keys filter. This parameter controls the filter used by both B<--dump-unique-keys> and its counterpart B<--warn-unique-keys>, described below. The filter works as follows: if a related set of keys has more than B unique keys, then none of them are listed. The default value is B, which causes the minimum number of keys to be reported. Increasing B above 1 will allow more unique keys to be reported. Thus, a value B will catch up to 1 error per set of related keys. A value B will catch up to two errors per set, but at the same time may produce more unwanted warnings. For the special case B some extra filtering is done to minimize unwanted warnings. For examples, unique keys in ALL CAPS are not reported for B. =item B to warn of possible misspelled hash keys The parameter B<--warn-unique-keys>, or B<-wuk>, can be used to produce a warning of a possible misspelled hash key during normal processing. It works like the previous B<-dump> version but writes to the standard error output if unique keys are found during normal formatting. For some scripts, this will produce unwanted warnings for a few keys, even though the filter described above attempts to avoid this. A way to avoid warnings for specific keys is to list them somewhere in the program in a B list. This will be seen during the key scan, and the then keys will not be considered unique. =item B to help locate misspelled hash keys The parameter B<--dump-similar-keys>, or B<-dsk>, provides another way to help locate errors in hash keys. It dumps a list of hash keys which are very similar but different. For example: perltidy -dsk File.pm >output.txt The lines in the output file contain pairs of similar keys, and the number of times each was found in the file. For example, the following line is from an actual script: recieve,receive,2,6 This tells us that the key C (a spelling error) occurs 2 times and the correct key C occurs 6 times: Note that if this error had occurred just once then it could have also been found with B<--dump-unique-keys> or B<--warn-unique-keys>. But since it occurs more than once, the B<--dump-similar-keys> option or its B<--warn-> version is needed to locate it. =item B, or B<-wsk>, to warn of hash keys which are similar but different. This is the like the B<--dump-similar-keys> option but writes to the error output file during normal formatting. In most cases, the warnings will be for perfectly valid hash keys. So this parameter is probably most useful for occasional debugging. See L<"Creating a new abbreviation"> for a convenient way to include it in a F<.perltidyrc>. =item B The default parameters which control the search for similar keys should be normally be adequate, but they can be modified if necessary. They are as follows: =over 4 =item B<--similar-keys-maximum-difference=n>, or B<-skmd=n>, specifies the maximum difference between two keys for similarity. The integer B gives the maximum number of differences to use when checking for hash key similarity. The default is B. The basic rules are that one difference is counted for each of the following conditions: =over 4 =item * a change in case of a letter, any number of times, such as C. This is implemented by making comparisons with lower case copies of the strings if any case change is detected. =item * one or more same-character changes, such as C. This is implemented by remembering any change such as B<-> to B<_> in this example, and counting it just once. =item * transposed characters, such as C =item * a missing or extra character, such as C or C =item * any other character difference, such as C =back To help filter out unwanted matches, an additional rule is that one extra difference is counted if the B letters are different when we ignore their case. For example, C<_xmin, _Xmin> has a difference of one because of the case change, but the first letter is the same except for the case change. So the difference is one and this pair will be reported with the default setting B. On the other hand, the pair C<_xmin, _ymin> has a different first letter which is not due to a case change, so the total difference score is 2, and it will not be reported with the default setting B. And this type of difference is unlikely to be an error. So the default value B<-skmd=1> will catch most common errors without producing excessive output, but for a more thorough check it can be increased to B. Values greater than 2 can produce a large amount output, so rather than use higher values, it might be better to dump all of the keys and examine them with the B<--dump-hash-keys> parameter described below. =item B<--similar-keys-minimum-length=n>, or B<-skml=n>, defines a minimum hash key length. Hash keys with fewer than B characters will be ignored when checking for similar keys. The default is B. =item B<--similar-keys-maximum-pairs=n>, or B<-skmp=n>, defines the maximum number of similar pairs to display Each similar pair found is displayed on one line of output, so this is equivalent to the maximum number of output lines. The default is 25. =back =item B to dump a list of hash keys The parameter B<--dump-hash-keys>, or B<-dhk>, dumps a list of all hash keys found by perltidy to the standard output and exits. It can produce a lot of output, but it might be useful as a last resort when searching for a hash key problem. For example: perltidy -dhk File.pm >output.txt The lines in the output file list the keys and number of occurrences. =item B The parameter B<--dump-mixed-call-parens>, or B<-dmcp>, provides information on the use of call parens within a program. It produces a list of keywords and sub names which occur both with and without parens. In other words, with a mixed style. This might be useful if one is working to standardize the call style for some particular keyword or function. For example, perltidy -dmcp somefile.pl >output.txt will analyze the text of F, write the results to F, and then immediately exit (like all B parameters). The output shows a list of operators and the number of times they were used with parens and the number of times without parens. For example, here is a small section of the output from one file in a past Perl distribution: k:length:17:9 k:open:30:9 k:pop:3:4 The first line shows that the C function occurs 17 times with parens and 9 times without parens. The 'k' indicates that C is a Perl builtin keyword ('U' would mean user-defined sub, and 'w' would mean unknown bareword). So from this partial output we see that the author had a preference for parens around the args of C and C, whereas C was about equally likely to have parens as not. More detailed information can be obtained with the parameters described in the next section. =item B The parameter B<--want-call-parens=s>, or B<-wcp=s>, can be used to produce a warning message if call parens are missing from selected functions. Likewise, B<--nowant-call-parens=s>, or B<-nwcp=s>, can warn if call parens exist for selected functions. When either of these parameters are set, perltidy will report any discrepancies from the requested style in its error output. Before using either of these parameters, it may be helpful to first use B<--dump-mixed-call-parens=s>, described in the previous section, to get an overview of the existing paren usage in a file. The string arguments B are space-separated lists of the names of the functions to be checked. The function names may be builtin keywords or user-defined subs. They may not include a package prefix or sigil. To illustrate, perltidy -wcp='length open' -nwcp='pop' somefile.pl means that the builtin functions C and C should have parens around their call args but C should not. The error output might contain lines such as: 2314:open FD_TO_CLOSE: no call parens 3652:pop (: has call parens 3783:length $DB: no call parens ... For builtin keywords which have both a block form and a trailing modifier form, such as C, only the trailing modifier form will be checked since parens are mandatory for the block form. The symbol B<&> may entered instead of a function name to mean all user-defined subs not explicitly listed. So the compact expression perltidy -wcp='&' somefile.pl means that calls to all user-defined subs in the file being processed should have their call arguments enclosed in parens. Perltidy does not have the ability to add or delete call parens because it is difficult to automate, so changes must be made manually. When adding or removing parentheses, it is essential to pay attention to operator precedence issues. For example, if the parens in the following statement are removed, then C<||> must be changed to C: open( IN, "<", $infile ) || die("cannot open $infile:$!\n"); Otherwise, the C<||> will operate on C<$infile> rather than the return value of C. =item B The parameter B<--dump-mismatched-args>, or B<-dma>, causes perltidy to examine the definitions of subroutines in a file, and calls to those subs, and report certain differences. Like all B<--dump> commands, it writes its report to standard output and exits immediately. For example perltidy -dma somefile.pl >results.txt Four types of issues are reported, types B, B, B, and B: =over 4 =item B calls made to a sub both with and without the B operator For example the following two lines would be reported as a mismatch: Fault(); and $self->Fault(); This may or may not be an error, but it is worth checking. It might become an error in the future if sub C starts to access C<$self>. =item B (B): the number of call args exceeds the expected number. =item B (B): the number of call args is less than the expected number. For example sub gnab_gib { my $self=shift; my ($v1,$v2)=@_; ... } $self->gnab_gib(42); In this case, the sub is expecting a total of three args (C<$self>, C<$v1>, and C<$v2>) but only receives two (C<$self> and C<42>), so an undercount is reported. This is not necessarily an error because the sub may allow for this possibility, but it is worth checking. Although it is not possible to automatically determine which sub args are optional, if optional sub args are enclosed in an extra set of parentheses, perltidy will take this a signal that they are optional and not issue a warning. So if the above example is written as sub gnab_gib { my $self = shift; my ( $v1, ($v2) ) = @_; # <-- $v2 is optional ...; } then perltidy will consider that the second arg is optional and not issue a warning for: $self->gnab_gib(42); For multiple default call args, place one set of parens around them all. Some examples: my ( ($v1) ) = @_; # <-- $v1 is optional my ( $v1, ( $v2, $v3 ) ) = @_; # <-- $v2, $v3 are optional =item B B a specific number of expected args for a sub could not be determined, but it is called with a specific number. This issue is reported for the B<--dump-> option but not the B<--warn-> option. =back B =over 4 =item * This option works best for subs which unpack call args in an orderly manner near the beginning of the sub from C<@_> and/or with C operations. It will also work for direct access to specific elements of the @_ array. However if the coding for arg extraction is complex then the number of sub args will be considered indeterminate and a count cannot be checked. =item * Sub calls made without parentheses around the args are not checked. =item * Anonymous subs and lexical subs (introduced with C) are not checked. =item * Only calls which appear to be to subs defined within the file being processed are checked. But note that a file may contain multiple packages. =back =item B. This is similar to the B<-dump> parameter described above except that any mismatches are reported in the error file and otherwise formatting continues normally. The basic usage is perltidy -wma somefile.pl Several companion controls are available to avoid unwanted error messages: =over 4 =item * B<--warn-mismatched-arg-types=s>, or B<-wmat=s>, can be used to select specific tests, type B (arrow test) or B (overcounts) or B (undercounts). All checks may be requested with B<-wmat='*'> or B<-wmat=1>. This is the default. To restrict the check to a specific warning type, set the string equal to the letter of that warning, any B, B, or B. For example perltidy -wmat='a o' somefile.pl will format F and report any arrow-type mismatches and overcount mismatches, but will skip undercount mismatches. =item * B<--warn-mismatched-arg-exclusion-list>, or B<-wmaxl=string>, can be given to skip the warning checks for a list of subroutine names, entered as a quoted string of space- or comma-separated names, without a package prefix. All subs with those names will be skipped, regardless of package. A leading and/or trailing B<*> on a name may be used to indicate a partial string match. =item * B<--warn-mismatched-arg-undercount-cutoff=n>, or B<-wmauc=n>, can be used to avoid B warnings when the expected number of args is less than B. Please note that this number B is the number of args from the point of view of the sub definition, so an object like C<$self> passed with an arrow operator counts as one arg. The default value is B. This has been found to allow most programs to pass without warnings, but it should be reduced if possible for better error checking. The minimum possible value of B needed to avoid triggering an error for a program can be determined by running with B<-wma -wmauc=0>. If there are undercount errors, a note at the bottom of the error output indicates the value of B required to avoid reporting them. As noted above for the parameter B<--dump-mismatched-args>, if optional call args are enclosed in separate parentheses, then perltidy will recognize them as optional args and avoid needless warnings. If this method is used, then B<-wmauc=0> should be used for maximal checking. =item * B<--warn-mismatched-arg-overcount-cutoff=n>, or B<-wmaoc=n>, can be used to avoid B warnings when the expected number of args is less than B. The default value is B. This avoids warning messages for subroutines which are dummy placeholders for possible expansion. =back To illustrate these controls, perltidy -wma -wmat='o u' -wmaxl='new old' -wmauc=2 somefile.pl means format F as usual and check for mismatched overcounts and undercounts but not arrows. Skip checking for any sub named C or C, and only warn of undercounts for subs expecting more than 2 args. =item B to find function calls where the number of requested values may disagree with sub return statements The parameter B<--dump-mismatched-returns>, or B<-dmr>, examines the return side of sub call statements. Like all B<--dump> commands, it writes its report to standard output and exits immediately. For example perltidy -dmr somefile.pl >results.txt The following types of issues are reported: =over 4 =item B calls requesting an array from a sub with no return statements. =item B calls requesting a scalar from a sub with no return statements. =item B (B): calls requesting an array with a count which exceeds the maximum number returned by the sub. =item B (B): calls requesting an array with a count which is below the maximum and which does not match a number returned by the sub. =item B calls requesting a scalar from a sub which only returns two or more items. =item B multiple array return sizes. =back Most of these issue types are illustrated with the following code sub macho { ... ( $name, $flags ); # 2 values but no 'return' statement } ( $name, $flags ) = macho(); # 'x' (want array, but no return) $name = macho(); # 'y' (want scalar but no return) sub wimp { ...; return ( $name, $flags ); # 2 values with 'return' statement } ( $name, $flags, $access) = wimp(); # 'o' (want array 3 > 2) ($name) = wimp(); # 'u' (want array 1 < 2) $name = wimp(); # 's' (want scalar but 2 values returned) The type B issue occurs when a sub has multiple returns of finite lists with different counts greater than 1, and not all of them are matched with calls. For example: sub find_libs { ...; return ( $libjava, $libjvm, $libhpi, $libawt ); # 4 items ...; return ( $libjava, $libawt ); # 2 items } my ( $libjava, $libjvm, $libhpi, $libawt ) = find_libs(); This analysis works by scanning all call statements and all sub return statements, and comparing the number of items wanted with the possible number of items returned. If a specific value for either of these numbers cannot be determined for a call then it cannot be checked. Since only return statements are scanned for return values, this analysis will not be useful for programming which relies on the default return mechanism, as in the first sub above. Note that the B policy B can be used to check for code in this situation. Reported issues are not necessarily errors, but they might be, or they might indicate potentially confusing code. =item B to issue warnings when the number of requested values may disagree with sub return statements This is similar to the B<-dump> parameter described above except that any mismatches are reported in the error file and otherwise formatting continues normally. The basic usage is perltidy -wmr somefile.pl The following companion controls are available to avoid unwanted error messages: =over 4 =item * B<--warn-mismatched-return-types=string>, or B<-wmrt=string>, can be used to limit checks. To restrict the checking, set the string equal to the letter(s) of that warning, any B, B, B, B, or B. For example perltidy -wmr -wmrt='x o s' somefile.pl will format F and report issue types B, B, and B but not types B and B. All checks may be requested with B<-wmrt='*'> or B<-wmrt=1>. This is the default if this parameter is not specified. =item * B<--warn-mismatched-return-exclusion-list>, or B<-wmrxl=string>, can be given to skip the warning checks for a list of subroutine names, entered as a quoted string of space- or comma-separated names, without a package prefix. All subs with those names will be skipped, regardless of package. A leading and/or trailing B<*> on a name may be used to indicate a partial string match. =back =back =head2 B The first $VERSION line of a file which might be eval'd by MakeMaker is passed through unchanged except for indentation. The default B<--pass-version-line>, or B<-pvl>, is to do this. Use B<--nopass-version-line>, or B<-npvl>, to deactivate this feature. If the AutoLoader module is used, perltidy will continue formatting code after seeing an __END__ line. The default B<--look-for-autoloader>, or B<-lal>, is to do this. Use B<--nolook-for-autoloader>, or B<-nlal>, to deactivate this feature. Likewise, if the SelfLoader module is used, perltidy will continue formatting code after seeing a __DATA__ line. The default B<--look-for-selfloader>, or B<-lsl>, is to do this. Use B<--nolook-for-selfloader>, or B<-nlsl>, to deactivate this feature. =head1 HTML OPTIONS =over 4 =item The B<-html> master switch The flag B<-html> causes perltidy to write an html file with extension F<.html>. So, for example, the following command perltidy -html somefile.pl will produce a syntax-colored html file named F which may be viewed with a browser. B: In this case, perltidy does not do any formatting to the input file, and it does not write a formatted file with extension F<.tdy>. This means that two perltidy runs are required to create a fully reformatted, html copy of a script. =item The B<-pre> flag for code snippets When the B<-pre> flag is given, only the pre-formatted section, within the C<

> and C<
> tags, will be output. This simplifies inclusion of the output in other files. The default is to output a complete web page. =item The B<-nnn> flag for line numbering When the B<-nnn> flag is given, the output lines will be numbered. =item The B<-toc>, or B<--html-table-of-contents> flag By default, a table of contents to packages and subroutines will be written at the start of html output. Use B<-ntoc> to prevent this. This might be useful, for example, for a pod document which contains a number of unrelated code snippets. This flag only influences the code table of contents; it has no effect on any table of contents produced by pod2html (see next item). =item The B<-pod>, or B<--pod2html> flag There are two options for formatting pod documentation. The default is to pass the pod through the Pod::Html module (which forms the basis of the pod2html utility). Any code sections are formatted by perltidy, and the results then merged. Note: perltidy creates a temporary file when Pod::Html is used; see L<"FILES">. Also, Pod::Html creates temporary files for its cache. NOTE: Perltidy counts the number of C<=cut> lines, and either moves the pod text to the top of the html file if there is one C<=cut>, or leaves the pod text in its original order (interleaved with code) otherwise. Most of the flags accepted by pod2html may be included in the perltidy command line, and they will be passed to pod2html. In some cases, the flags have a prefix C to emphasize that they are for the pod2html, and this prefix will be removed before they are passed to pod2html. The flags which have the additional C prefix are: --[no]podheader --[no]podindex --[no]podrecurse --[no]podquiet --[no]podverbose --podflush The flags which are unchanged from their use in pod2html are: --backlink=s --cachedir=s --htmlroot=s --libpods=s --title=s --podpath=s --podroot=s where 's' is an appropriate character string. Not all of these flags are available in older versions of Pod::Html. See your Pod::Html documentation for more information. The alternative, indicated with B<-npod>, is not to use Pod::Html, but rather to format pod text in italics (or whatever the stylesheet indicates), without special html markup. This is useful, for example, if pod is being used as an alternative way to write comments. =item The B<-frm>, or B<--frames> flag By default, a single html output file is produced. This can be changed with the B<-frm> option, which creates a frame holding a table of contents in the left panel and the source code in the right side. This simplifies code browsing. Assume, for example, that the input file is F. Then, for default file extension choices, these three files will be created: MyModule.pm.html - the frame MyModule.pm.toc.html - the table of contents MyModule.pm.src.html - the formatted source code Obviously this file naming scheme requires that output be directed to a real file (as opposed to, say, standard output). If this is not the case, or if the file extension is unknown, the B<-frm> option will be ignored. =item The B<-text=s>, or B<--html-toc-extension> flag Use this flag to specify the extra file extension of the table of contents file when html frames are used. The default is "toc". See L<"Specifying File Extensions">. =item The B<-sext=s>, or B<--html-src-extension> flag Use this flag to specify the extra file extension of the content file when html frames are used. The default is "src". See L<"Specifying File Extensions">. =item The B<-hent>, or B<--html-entities> flag This flag controls the use of Html::Entities for html formatting. By default, the module Html::Entities is used to encode special symbols. This may not be the right thing for some browser/language combinations. Use --nohtml-entities or -nhent to prevent this. =item B