X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlform.pod;h=fac7efca35cb6b87623fecacfc1307da4c856cf8;hb=83272a45226e83bd136d713158e9b44ace2dbc8d;hp=0b2a68c3d46352fc4354a0344a9388493fbd590a;hpb=7b8d334a971230040a212bc5038097b3f600a094;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlform.pod b/pod/perlform.pod index 0b2a68c..fac7efc 100644 --- a/pod/perlform.pod +++ b/pod/perlform.pod @@ -60,11 +60,13 @@ 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 multi-line, -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 because the pragma is tied to the block structure of the program, and, for historical reasons, formats exist outside that block structure. See L 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.