This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldoc -f stat (perlfunc.pod)
[perl5.git] / pod / perlform.pod
index 75351b6..fac7efc 100644 (file)
@@ -20,8 +20,8 @@ apart from all the other "types" in Perl.  This means that if you have a
 function named "Foo", it is not the same thing as having a format named
 "Foo".  However, the default name for the format associated with a given
 filehandle is the same as the name of the filehandle.  Thus, the default
-format for STDOUT is name "STDOUT", and the default format for filehandle
-TEMP is name "TEMP".  They just look the same.  They aren't.
+format for STDOUT is named "STDOUT", and the default format for filehandle
+TEMP is named "TEMP".  They just look the same.  They aren't.
 
 Output record formats are declared as follows:
 
@@ -53,18 +53,20 @@ that substitute values into the line.  Each field in a picture line starts
 with either "@" (at) or "^" (caret).  These lines do not undergo any kind
 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 multiline text block filling.  The length of the field
+to do rudimentary multi-line text block filling.  The length of the field
 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.
 
 As an alternate form of right justification, you may also use "#"
-characters (with an optional ".") to specify a numeric field.  This way
-you can line up the decimal points.  If any value supplied for these
-fields contains a newline, only the text up to the newline is printed.
-Finally, the special field "@*" can be used for printing multiline,
-nontruncated values; it should appear by itself on a line.
+characters (with an optional ".") to specify a numeric field. This way
+you can line up the decimal points. With a "0" (zero) instead of the
+first "#", the formatted number will be padded with leading zeroes if
+necessary. If any value supplied for these fields contains a newline,
+only the text up to the newline is printed. Finally, the special field
+"@*" can be used for printing multi-line, nontruncated values; it
+should appear by itself on a line.
 
 The values are specified on the following line in the same order as
 the picture fields.  The expressions providing the values should be
@@ -187,7 +189,7 @@ stage in the expression to single-step the debugger through):
 
 If you use the English module, you can even read the variable names:
 
-    use English;
+    use English '-no_match_vars';
     $ofh = select(OUTF);
     $FORMAT_NAME     = "My_Other_Format";
     $FORMAT_TOP_NAME = "My_Top_Format";
@@ -233,11 +235,11 @@ of the page, however wide it is."  You have to specify where it goes.
 The truly desperate can generate their own format on the fly, based
 on the current number of columns, and then eval() it:
 
-    $format  = "format STDOUT = \n";
-             . '^' . '<' x $cols . "\n";
-             . '$entry' . "\n";
-             . "\t^" . "<" x ($cols-8) . "~~\n";
-             . '$entry' . "\n";
+    $format  = "format STDOUT = \n"
+             . '^' . '<' x $cols . "\n"
+             . '$entry' . "\n"
+             . "\t^" . "<" x ($cols-8) . "~~\n"
+             . '$entry' . "\n"
              . ".\n";
     print $format if $Debugging;
     eval $format;
@@ -295,7 +297,7 @@ For example:
 
     print "Wow, I just stored `$^A' in the accumulator!\n";
 
-Or to make an swrite() subroutine which is to write() what sprintf()
+Or to make an swrite() subroutine, which is to write() what sprintf()
 is to printf(), do this:
 
     use Carp;
@@ -315,18 +317,18 @@ is to printf(), do this:
 
 =head1 WARNINGS
 
-The lone dot that ends a format can also prematurely end an email
+The lone dot that ends a format can also prematurely end a mail
 message passing through a misconfigured Internet mailer (and based on
 experience, such misconfiguration is the rule, not the exception).  So
-when sending format code through email, you should indent it so that
+when sending format code through mail, you should indent it so that
 the format-ending dot is not on the left margin; this will prevent
-email cutoff.
+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 which unconditionally use information
+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
@@ -335,3 +337,12 @@ 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.
+
+Inside of an expression, the whitespace characters \n, \t and \f are
+considered to be equivalent to a single space.  Thus, you could think
+of this filter being applied to each value in the format:
+
+ $value =~ tr/\n\t\f/ /;
+
+The remaining whitespace character, \r, forces the printing of a new
+line if allowed by the picture line.