/usr/share/perl5/pod
NameSizeModeActions
perl.pod162700644editdlrm
perl56delta.pod1072010644editdlrm
perl58delta.pod1151650644editdlrm
perl561delta.pod1247130644editdlrm
perl581delta.pod380610644editdlrm
perl582delta.pod44700644editdlrm
perl583delta.pod63350644editdlrm
perl584delta.pod73630644editdlrm
perl585delta.pod58890644editdlrm
perl586delta.pod46510644editdlrm
perl587delta.pod83570644editdlrm
perl588delta.pod252720644editdlrm
perl589delta.pod539000644editdlrm
perl5004delta.pod562400644editdlrm
perl5005delta.pod342830644editdlrm
perl5100delta.pod555350644editdlrm
perl5101delta.pod438880644editdlrm
perl5120delta.pod892720644editdlrm
perl5121delta.pod101410644editdlrm
perl5122delta.pod96030644editdlrm
perl5123delta.pod41000644editdlrm
perl5124delta.pod36720644editdlrm
perl5125delta.pod76830644editdlrm
perl5140delta.pod1443240644editdlrm
perl5141delta.pod79660644editdlrm
perl5142delta.pod68920644editdlrm
perl5143delta.pod77600644editdlrm
perl5144delta.pod63270644editdlrm
perl5160delta.pod1336510644editdlrm
perl5161delta.pod61420644editdlrm
perl5162delta.pod35940644editdlrm
perl5163delta.pod40850644editdlrm
perl5180delta.pod1194310644editdlrm
perl5181delta.pod65950644editdlrm
perl5182delta.pod53350644editdlrm
perl5184delta.pod46420644editdlrm
perl5200delta.pod1156990644editdlrm
perl5201delta.pod108990644editdlrm
perl5202delta.pod125090644editdlrm
perl5203delta.pod93920644editdlrm
perl5220delta.pod1309630644editdlrm
perl5221delta.pod107670644editdlrm
perl5222delta.pod126290644editdlrm
perl5223delta.pod84560644editdlrm
perl5224delta.pod44600644editdlrm
perl5240delta.pod649270644editdlrm
perl5241delta.pod82150644editdlrm
perl5242delta.pod41130644editdlrm
perl5243delta.pod114280644editdlrm
perl5244delta.pod45100644editdlrm
perl5260delta.pod1018360644editdlrm
perl5261delta.pod79270644editdlrm
perl5262delta.pod78800644editdlrm
perl5263delta.pod70630644editdlrm
perl5280delta.pod721130644editdlrm
perlaix.pod204370644editdlrm
perlamiga.pod57490644editdlrm
perlandroid.pod78710644editdlrm
perlapi.pod4435350644editdlrm
perlapio.pod192850644editdlrm
perlartistic.pod70100644editdlrm
perlbook.pod83380644editdlrm
perlboot.pod2940644editdlrm
perlbot.pod3040644editdlrm
perlbs2000.pod80580644editdlrm
perlcall.pod567060644editdlrm
perlce.pod146020644editdlrm
perlcheat.pod44810644editdlrm
perlclib.pod96190644editdlrm
perlcn.pod46910644editdlrm
perlcommunity.pod72170644editdlrm
perlcygwin.pod271990644editdlrm
perldata.pod467430644editdlrm
perldbmfilter.pod49810644editdlrm
perldebguts.pod385350644editdlrm
perldebtut.pod221520644editdlrm
perldebug.pod392580644editdlrm
perldelta.pod70630644editdlrm
perldeprecation.pod181690644editdlrm
perldiag.pod2845720644editdlrm
perldos.pod105220644editdlrm
perldsc.pod256140644editdlrm
perldtrace.pod79580644editdlrm
perlebcdic.pod842330644editdlrm
perlembed.pod371960644editdlrm
perlexperiment.pod71950644editdlrm
perlfork.pod133550644editdlrm
perlform.pod166080644editdlrm
perlfreebsd.pod16100644editdlrm
perlfunc.pod3929570644editdlrm
perlgit.pod335090644editdlrm
perlgpl.pod138150644editdlrm
perlguts.pod1393290644editdlrm
perlhack.pod404450644editdlrm
perlhacktips.pod555090644editdlrm
perlhacktut.pod61530644editdlrm
perlhaiku.pod15080644editdlrm
perlhist.pod535460644editdlrm
perlhpux.pod305090644editdlrm
perlhurd.pod19930644editdlrm
perlintern.pod545720644editdlrm
perlinterp.pod336870644editdlrm
perlintro.pod221190644editdlrm
perliol.pod341850644editdlrm
perlipc.pod708290644editdlrm
perlirix.pod43950644editdlrm
perljp.pod75210644editdlrm
perlko.pod122590644editdlrm
perllexwarn.pod3550644editdlrm
perllinux.pod14880644editdlrm
perllocale.pod686780644editdlrm
perllol.pod95800644editdlrm
perlmacos.pod10010644editdlrm
perlmacosx.pod120600644editdlrm
perlmod.pod262500644editdlrm
perlmodinstall.pod127920644editdlrm
perlmodlib.pod764820644editdlrm
perlmodstyle.pod225750644editdlrm
perlmroapi.pod32120644editdlrm
perlnetware.pod66480644editdlrm
perlnewmod.pod110360644editdlrm
perlnumber.pod83530644editdlrm
perlobj.pod355370644editdlrm
perlootut.pod267830644editdlrm
perlop.pod1362520644editdlrm
perlopenbsd.pod12040644editdlrm
perlopentut.pod94550644editdlrm
perlos2.pod933510644editdlrm
perlos390.pod156740644editdlrm
perlos400.pod47680644editdlrm
perlpacktut.pod512820644editdlrm
perlperf.pod498810644editdlrm
perlplan9.pod51250644editdlrm
perlpod.pod221960644editdlrm
perlpodspec.pod684760644editdlrm
perlpolicy.pod256290644editdlrm
perlport.pod876020644editdlrm
perlpragma.pod51760644editdlrm
perlqnx.pod66730644editdlrm
perlre.pod1209010644editdlrm
perlreapi.pod303340644editdlrm
perlrebackslash.pod318170644editdlrm
perlrecharclass.pod490290644editdlrm
perlref.pod353040644editdlrm
perlreftut.pod187900644editdlrm
perlreguts.pod383280644editdlrm
perlrepository.pod5090644editdlrm
perlrequick.pod184970644editdlrm
perlreref.pod147440644editdlrm
perlretut.pod1212570644editdlrm
perlriscos.pod15290644editdlrm
perlrun.pod535500644editdlrm
perlsec.pod261840644editdlrm
perlsolaris.pod298220644editdlrm
perlsource.pod68760644editdlrm
perlstyle.pod86300644editdlrm
perlsub.pod729670644editdlrm
perlsymbian.pod153590644editdlrm
perlsyn.pod445120644editdlrm
perlsynology.pod77780644editdlrm
perlthrtut.pod464590644editdlrm
perltie.pod386070644editdlrm
perltoc.pod6941710644editdlrm
perltodo.pod3760644editdlrm
perltooc.pod2940644editdlrm
perltoot.pod2940644editdlrm
perltrap.pod106200644editdlrm
perltru64.pod84920644editdlrm
perltw.pod44770644editdlrm
perlunicode.pod824910644editdlrm
perlunicook.pod254880644editdlrm
perlunifaq.pod136470644editdlrm
perluniintro.pod383400644editdlrm
perluniprops.pod2853060644editdlrm
perlunitut.pod79510644editdlrm
perlutil.pod76400644editdlrm
perlvar.pod783640644editdlrm
perlvms.pod508230644editdlrm
perlvos.pod38430644editdlrm
perlwin32.pod392980644editdlrm
perlxs.pod789200644editdlrm
perlxstut.pod500950644editdlrm
perlxstypemap.pod240010644editdlrm
Edit: /usr/share/perl5/pod/perlform.pod (16608B)
=head1 NAME X X X perlform - Perl formats =head1 DESCRIPTION Perl has a mechanism to help you generate simple reports and charts. 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 are 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. 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 Formats, like packages and subroutines, are declared rather than executed, so they may occur at any point in your program. (Usually it's best to keep them all together though.) They have their own namespace 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 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: format NAME = FORMLIST . If the name is omitted, format "STDOUT" is defined. A single "." in column 1 is used to terminate a format. FORMLIST consists of a sequence of lines, each of which may be one of three types: =over 4 =item 1. A comment, indicated by putting a '#' in the first column. =item 2. A "picture" line giving the format for one output line. =item 3. An argument line supplying values to plug into the previous picture line. =back Picture lines contain output field definitions, intermingled with 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 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 justification | pad character for centering > 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 @* variable width field for a multi-line value ^* variable width field for next line of a multi-line value ~ suppress line with all fields empty ~~ repeat line until all fields are exhausted Each field in a picture line starts with either "@" (at) or "^" (caret), indicating what we'll call, respectively, a "regular" or "special" field. The choice of pad characters determines whether a field is textual or numeric. The tilde operators are not part of a field. Let's look at the various possibilities in detail. =head2 Text Fields X The length of the field is supplied by padding out the field with multiple "E", "E", or "|" characters to specify a non-numeric field with, respectively, left justification, right justification, or centering. For a regular field, the value (up to the first newline) is taken and printed according to the selected justification, truncating excess characters. If you terminate a text field with "...", three dots will be shown if the value is truncated. A special text field may be used to do rudimentary multi-line text block filling; see L for details. Example: format STDOUT = @<<<<<< @|||||| @>>>>>> "left", "middle", "right" . Output: left middle right =head2 Numeric Fields X<#> X Using "#" as a padding character specifies a numeric field, with right justification. An optional "." defines the position of the decimal point. With a "0" (zero) instead of the first "#", the formatted number will be padded with leading zeroes if necessary. A special numeric field is blanked out if the value is undefined. If the resulting value would exceed the width specified the field is filled with "#" as overflow evidence. Example: format STDOUT = @### @.### @##.### @### @### ^#### 42, 3.1415, undef, 0, 10000, undef . Output: 42 3.142 0.000 0 #### =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 X<^*> 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. The variable will I be restored. Example: $text = "line 1\nline 2\nline 3"; format STDOUT = Text: ^* $text ~~ ^* $text . Output: Text: line 1 line 2 line 3 =head2 Specifying Values X The values are specified on the following format line in the same order as the picture fields. The expressions providing the values must be separated by commas. They are all evaluated in a list context 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. 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 an embedded "."), the character used for the decimal point is determined by the current LC_NUMERIC locale if C 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 and L for more information. =head2 Using Fill Mode X On text fields the caret enables a kind of fill mode. Instead of an arbitrary expression, the value supplied must be a scalar variable that contains a text string. Perl puts the next portion 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. (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 (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 list of the desired characters. Normally you would use a sequence of fields in a vertical stack associated with the same scalar variable to print out a block of text. You might wish to end the final field with the text "...", which will appear in the output if the text was too long to appear in its entirety. =head2 Suppressing Lines Where All Fields Are Void X Using caret fields can produce lines where all fields are blank. You can suppress such lines by putting a "~" (tilde) character anywhere in the line. The tilde will be translated to a space upon output. =head2 Repeating Format Lines X 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, i.e. undefined. For special (caret) text fields this will occur sooner or later, but if you use a text field of the at variety, the expression you supply had better not give the same value every time forever! (C is a simple example that would work.) Don't use a regular (at) numeric field in such lines, because it will never go blank. =head2 Top of Form Processing X X X
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 L. Examples: # a report on the /etc/passwd file format STDOUT_TOP = Passwd File Name Login Office Uid Gid Home ------------------------------------------------------------------ . format STDOUT = @<<<<<<<<<<<<<<<<<< @||||||| @<<<<<<@>>>> @>>>> @<<<<<<<<<<<<<<<<< $name, $login, $office,$uid,$gid, $home . # a report from a bug report form format STDOUT_TOP = Bug Reports @<<<<<<<<<<<<<<<<<<<<<<< @||| @>>>>>>>>>>>>>>>>>>>>>>> $system, $%, $date ------------------------------------------------------------------ . format STDOUT = Subject: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $subject Index: @<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $index, $description Priority: @<<<<<<<<<< Date: @<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $priority, $date, $description From: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $from, $description Assigned to: @<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $programmer, $description ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $description ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $description ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $description ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<< $description ~ ^<<<<<<<<<<<<<<<<<<<<<<<... $description . It is possible to intermix print()s with write()s on the same output channel, but you'll have to handle C<$-> (C<$FORMAT_LINES_LEFT>) yourself. =head2 Format Variables X X 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<$|> (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: select((select(OUTF), $~ = "My_Other_Format", $^ = "My_Top_Format" )[0]); 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 an intermediary stage in the expression to single-step the debugger through): $ofh = select(OUTF); $~ = "My_Other_Format"; $^ = "My_Top_Format"; select($ofh); If you use the English module, you can even read the variable names: use English; $ofh = select(OUTF); $FORMAT_NAME = "My_Other_Format"; $FORMAT_TOP_NAME = "My_Top_Format"; select($ofh); But you still have those funny select()s. So just use the FileHandle module. Now, you can access these special variables using lowercase method names instead: use FileHandle; format_name OUTF "My_Other_Format"; format_top_name OUTF "My_Top_Format"; Much better! =head1 NOTES 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: format Ident = @<<<<<<<<<<<<<<< &commify($n) . To get a real at or caret into the field, do this: format Ident = I have an @ here. "@" . To center a whole line of text, do something like this: format Ident = @||||||||||||||||||||||||||||||||||||||||||||||| "Some text line" . There is no builtin way to say "float this to the right hand side 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" . ".\n"; print $format if $Debugging; eval $format; die $@ if $@; Which would generate a format looking something like this: format STDOUT = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $entry ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $entry . Here's a little program that's somewhat like fmt(1): format = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~ $_ . $/ = ''; while (<>) { s/\s*\n\s*/ /g; write; } =head2 Footers X X