This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldelta for 7ef30830/#114018
[perl5.git] / pod / perlform.pod
index 6e104bb..fc5d02b 100644 (file)
@@ -1,4 +1,5 @@
 =head1 NAME
+X<format> X<report> X<chart>
 
 perlform - Perl formats
 
@@ -12,6 +13,7 @@ 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 BASIC's PRINT USING statement.  Think of it
 as a poor man's nroff(1).
+X<nroff>
 
 Formats, like packages and subroutines, are declared rather than
 executed, so they may occur at any point in your program.  (Usually it's
@@ -54,13 +56,16 @@ literal text. These lines do not undergo any kind of variable interpolation.
 Field definitions are made up from a set of characters, for starting and
 extending a field to its desired width. This is the complete set of
 characters for field definitions:
-  
+X<format, picture line>
+X<@> X<^> X<< < >> X<< | >> X<< > >> X<#> X<0> X<.> X<...>
+X<@*> X<^*> X<~> X<~~>
+
    @    start of regular field
    ^    start of special field
-   <    pad character for left adjustification
+   <    pad character for left justification
    |    pad character for centering
-   >    pad character for right adjustificat
-   #    pad character for a right justified numeric field
+   >    pad character for right justification
+   #    pad character for a right-justified numeric field
    0    instead of first #: pad number with leading zeroes
    .    decimal point within a numeric field
    ...  terminate a text field, show "..." as truncation evidence
@@ -77,6 +82,7 @@ the various possibilities in detail.
 
 
 =head2 Text Fields
+X<format, text field>
 
 The length of the field is supplied by padding out the field with multiple 
 "E<lt>", "E<gt>", or "|" characters to specify a non-numeric field with,
@@ -97,6 +103,7 @@ multi-line text block filling; see L</Using Fill Mode> for details.
 
 
 =head2 Numeric Fields
+X<#> X<format, numeric field>
 
 Using "#" as a padding character specifies a numeric field, with
 right justification. An optional "." defines the position of the
@@ -115,16 +122,18 @@ filled with "#" as overflow evidence.
         42   3.142     0.000     0   ####
 
 
-=head2 The Field @* for Variable Width Multi-Line Text
+=head2 The Field @* for Variable-Width Multi-Line Text
+X<@*>
 
 The field "@*" can be used for printing multi-line, nontruncated
 values; it should (but need not) appear by itself on a line. A final
 line feed is chomped off, but all other characters are emitted verbatim.
 
 
-=head2 The Field ^* for Variable Width One-line-at-a-time Text
+=head2 The Field ^* for Variable-Width One-line-at-a-time Text
+X<^*>
 
-Like "@*", this is a variable width field. The value supplied must be a 
+Like "@*", this is a variable-width field. The value supplied must be a 
 scalar variable. Perl puts the first line (up to the first "\n") of the 
 text into the field, and then chops off the front of the string so that 
 the next time the variable is referenced, more of the text can be printed. 
@@ -145,6 +154,7 @@ The variable will I<not> be restored.
 
 
 =head2 Specifying Values
+X<format, specifying values>
 
 The values are specified on the following format line in the same order as
 the picture fields.  The expressions providing the values must be
@@ -156,13 +166,14 @@ 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
+point is determined by the current LC_NUMERIC locale if C<use locale> is in
+effect.  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.
 
 
 =head2 Using Fill Mode
+X<format, fill mode>
 
 On text fields the caret enables a kind of fill mode.  Instead of an
 arbitrary expression, the value supplied must be a scalar variable
@@ -171,7 +182,7 @@ the field, and then chops off the front of the string so that the next time
 the variable is referenced, more of the text can be printed.  (Yes, this
 means that the variable itself is altered during execution of the write()
 call, and is not restored.)  The next portion of text is determined by
-a crude line breaking algorithm. You may use the carriage return character
+a crude line-breaking algorithm. You may use the carriage return character
 (C<\r>) to force a line break. You can change which characters are legal 
 to break on by changing the variable C<$:> (that's 
 $FORMAT_LINE_BREAK_CHARACTERS if you're using the English module) to a 
@@ -184,6 +195,7 @@ if the text was too long to appear in its entirety.
 
 
 =head2 Suppressing Lines Where All Fields Are Void
+X<format, suppressing lines>
 
 Using caret fields can produce lines where all fields are blank. You can
 suppress such lines by putting a "~" (tilde) character anywhere in the
@@ -191,6 +203,7 @@ line.  The tilde will be translated to a space upon output.
 
 
 =head2 Repeating Format Lines
+X<format, repeating lines>
 
 If you put two contiguous tilde characters "~~" anywhere into a line,
 the line will be repeated until all the fields on the line are exhausted,
@@ -202,6 +215,7 @@ field in such lines, because it will never go blank.
 
 
 =head2 Top of Form Processing
+X<format, top of form> X<top> X<header>
 
 Top-of-form processing is by default handled by a format with the
 same name as the current filehandle with "_TOP" concatenated to it.
@@ -256,6 +270,8 @@ channel, but you'll have to handle C<$-> (C<$FORMAT_LINES_LEFT>)
 yourself.
 
 =head2 Format Variables
+X<format variables>
+X<format, variables>
 
 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>).
@@ -275,7 +291,7 @@ one to affect them:
 Pretty ugly, eh?  It's a common idiom though, so don't be too surprised
 when you see it.  You can at least use a temporary variable to hold
 the previous filehandle: (this is a much better approach in general,
-because not only does legibility improve, you now have intermediary
+because not only does legibility improve, you now have an intermediary
 stage in the expression to single-step the debugger through):
 
     $ofh = select(OUTF);
@@ -365,6 +381,7 @@ Here's a little program that's somewhat like fmt(1):
  }
 
 =head2 Footers
+X<format, footer> X<footer>
 
 While $FORMAT_TOP_NAME contains the name of the current header format,
 there is no corresponding mechanism to automatically do the same thing
@@ -376,11 +393,12 @@ by checking $FORMAT_LINES_LEFT before each write() and print the footer
 yourself if necessary.
 
 Here's another strategy: Open a pipe to yourself, using C<open(MYSELF, "|-")>
-(see L<perlfunc/open()>) and always write() to MYSELF instead of STDOUT.
+(see L<perlfunc/open>) and always write() to MYSELF instead of 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
+X<format, internals>
 
 For low-level access to the formatting mechanism.  you may use formline()
 and access C<$^A> (the $ACCUMULATOR variable) directly.
@@ -391,7 +409,7 @@ For example:
     @<<<  @|||  @>>>
     END
 
-    print "Wow, I just stored `$^A' in the accumulator!\n";
+    print "Wow, I just stored '$^A' in the accumulator!\n";
 
 Or to make an swrite() subroutine, which is to write() what sprintf()
 is to printf(), do this:
@@ -422,19 +440,15 @@ SMTP cutoff.
 
 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.)
-
-Formats are the only part of Perl that 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.
-
-Within strings that are to be displayed in a fixed length text field,
+variable.
+
+If a program's environment specifies an LC_NUMERIC locale and C<use
+locale> is in effect when the format is declared, the locale is used
+to specify the decimal point character in formatted output.  Formatted
+output cannot be controlled by C<use locale> at the time when write()
+is called. See L<perllocale> for further discussion of locale handling.
+
+Within strings that are to be displayed in a fixed-length text field,
 each control character is substituted by a space. (But remember the
 special meaning of C<\r> when using fill mode.) This is done to avoid
 misalignment when control characters "disappear" on some output media.