=head1 DESCRIPTION
Perl has a mechanism to help you generate simple reports and charts. To
-facilitate this, Perl helps you lay out your output page in your code in a
-fashion that's close to how it will look when it's printed. It can keep
-track of things like how many lines on a page, what page you're, when to
+facilitate this, Perl helps you code up your output page
+close to how it will look when it's printed. It can keep
+track of things like how many lines on a page, what page you're on, when to
print page headers, etc. Keywords are borrowed from FORTRAN:
format() to declare and write() to execute; see their entries in
L<perlfunc>. Fortunately, the layout is much more legible, more like
of variable interpolation. The at field (not to be confused with the array
marker @) is the normal kind of field; the other kind, caret fields, are used
to do rudimentary multi-line text block filling. The length of the field
-is supplied by padding out the field with multiple "<", ">", or "|"
+is supplied by padding out the field with multiple "E<lt>", "E<gt>", or "|"
characters to specify, respectively, left justification, right
justification, or centering. If the variable would exceed the width
specified, it is truncated.
before the line is processed, so a single list expression could produce
multiple list elements. The expressions may be spread out to more than
one line if enclosed in braces. If so, the opening brace must be the first
-token on the first line.
+token on the first line. If an expression evaluates to a number with a
+decimal part, and if the corresponding picture specifies that the decimal
+part should appear in the output (that is, any picture except multiple "#"
+characters B<without> an embedded "."), the character used for the decimal
+point is B<always> determined by the current LC_NUMERIC locale. This
+means that, if, for example, the run-time environment happens to specify a
+German locale, "," will be used instead of the default ".". See
+L<perllocale> and L<"WARNINGS"> for more information.
Picture fields that begin with ^ rather than @ are treated specially.
With a # field, the field is blanked out if the value is undefined. For
Top-of-form processing is by default handled by a format with the
same name as the current filehandle with "_TOP" concatenated to it.
-It's triggered at the top of each page. See <perlfunc/write()>.
+It's triggered at the top of each page. See L<perlfunc/write>.
Examples:
.
It is possible to intermix print()s with write()s on the same output
-channel, but you'll have to handle $- ($FORMAT_LINES_LEFT)
+channel, but you'll have to handle C<$-> (C<$FORMAT_LINES_LEFT>)
yourself.
=head2 Format Variables
-The current format name is stored in the variable C<$~> ($FORMAT_NAME),
-and the current top of form format name is in C<$^> ($FORMAT_TOP_NAME).
-The current output page number is stored in C<$%> ($FORMAT_PAGE_NUMBER),
-and the number of lines on the page is in C<$=> ($FORMAT_LINES_PER_PAGE).
+The current format name is stored in the variable C<$~> (C<$FORMAT_NAME>),
+and the current top of form format name is in C<$^> (C<$FORMAT_TOP_NAME>).
+The current output page number is stored in C<$%> (C<$FORMAT_PAGE_NUMBER>),
+and the number of lines on the page is in C<$=> (C<$FORMAT_LINES_PER_PAGE>).
Whether to autoflush output on this handle is stored in C<$|>
-($OUTPUT_AUTOFLUSH). The string output before each top of page (except
-the first) is stored in C<$^L> ($FORMAT_FORMFEED). These variables are
+(C<$OUTPUT_AUTOFLUSH>). The string output before each top of page (except
+the first) is stored in C<$^L> (C<$FORMAT_FORMFEED>). These variables are
set on a per-filehandle basis, so you'll need to select() into a different
one to affect them:
=head1 NOTES
-Since the values line may contain arbitrary expressions (for at fields,
+Because the values line may contain arbitrary expressions (for at fields,
not caret fields), you can farm out more sophisticated processing
to other functions, like sprintf() or one of your own. For example:
Here's another strategy; open a pipe to yourself, using C<open(MESELF, "|-")>
(see L<perlfunc/open()>) and always write() to MESELF instead of
-STDOUT. Have your child process postprocesses its STDIN to rearrange
+STDOUT. Have your child process massage its STDIN to rearrange
headers and footers however you like. Not very convenient, but doable.
=head2 Accessing Formatting Internals
END
print $string;
-=head1 WARNING
+=head1 WARNINGS
Lexical variables (declared with "my") are not visible within a
format unless the format is declared within the scope of the lexical
variable. (They weren't visible at all before version 5.001.) Furthermore,
lexical aliases will not be compiled correctly: see
L<perlfunc/my> for other issues.
+
+Formats are the only part of Perl which unconditionally use information
+from a program's locale; if a program's environment specifies an
+LC_NUMERIC locale, it is always used to specify the decimal point
+character in formatted output. Perl ignores all other aspects of locale
+handling unless the C<use locale> pragma is in effect. Formatted output
+cannot be controlled by C<use locale> because the pragma is tied to the
+block structure of the program, and, for historical reasons, formats
+exist outside that block structure. See L<perllocale> for further
+discussion of locale handling.