Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man1 / perlform.1
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "PERLFORM 1"
132.TH PERLFORM 1 "2002-06-08" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134perlform \- Perl formats
135.SH "DESCRIPTION"
136.IX Header "DESCRIPTION"
137Perl has a mechanism to help you generate simple reports and charts. To
138facilitate this, Perl helps you code up your output page close to how it
139will look when it's printed. It can keep track of things like how many
140lines are on a page, what page you're on, when to print page headers,
141etc. Keywords are borrowed from \s-1FORTRAN:\s0 \fIformat()\fR to declare and \fIwrite()\fR
142to execute; see their entries in perlfunc. Fortunately, the layout is
143much more legible, more like \s-1BASIC\s0's \s-1PRINT\s0 \s-1USING\s0 statement. Think of it
144as a poor man's \fInroff\fR\|(1).
145.PP
146Formats, like packages and subroutines, are declared rather than
147executed, so they may occur at any point in your program. (Usually it's
148best to keep them all together though.) They have their own namespace
149apart from all the other \*(L"types\*(R" in Perl. This means that if you have a
150function named \*(L"Foo\*(R", it is not the same thing as having a format named
151\&\*(L"Foo\*(R". However, the default name for the format associated with a given
152filehandle is the same as the name of the filehandle. Thus, the default
153format for \s-1STDOUT\s0 is named \*(L"\s-1STDOUT\s0\*(R", and the default format for filehandle
154\&\s-1TEMP\s0 is named \*(L"\s-1TEMP\s0\*(R". They just look the same. They aren't.
155.PP
156Output record formats are declared as follows:
157.PP
158.Vb 3
159\& format NAME =
160\& FORMLIST
161\& .
162.Ve
163.PP
164If name is omitted, format \*(L"\s-1STDOUT\s0\*(R" is defined. \s-1FORMLIST\s0 consists of
165a sequence of lines, each of which may be one of three types:
166.IP "1." 4
167A comment, indicated by putting a '#' in the first column.
168.IP "2." 4
169A \*(L"picture\*(R" line giving the format for one output line.
170.IP "3." 4
171An argument line supplying values to plug into the previous picture line.
172.PP
173Picture lines are printed exactly as they look, except for certain fields
174that substitute values into the line. Each field in a picture line starts
175with either \*(L"@\*(R" (at) or \*(L"^\*(R" (caret). These lines do not undergo any kind
176of variable interpolation. The at field (not to be confused with the array
177marker @) is the normal kind of field; the other kind, caret fields, are used
178to do rudimentary multi-line text block filling. The length of the field
179is supplied by padding out the field with multiple "<\*(L", \*(R">\*(L", or \*(R"|"
180characters to specify, respectively, left justification, right
181justification, or centering. If the variable would exceed the width
182specified, it is truncated.
183.PP
184As an alternate form of right justification, you may also use \*(L"#\*(R"
185characters (with an optional \*(L".\*(R") to specify a numeric field. This way
186you can line up the decimal points. With a \*(L"0\*(R" (zero) instead of the
187first \*(L"#\*(R", the formatted number will be padded with leading zeroes if
188necessary. If any value supplied for these fields contains a newline,
189only the text up to the newline is printed. Finally, the special field
190\&\*(L"@*\*(R" can be used for printing multi\-line, nontruncated values; it
191should appear by itself on a line.
192.PP
193The values are specified on the following line in the same order as
194the picture fields. The expressions providing the values should be
195separated by commas. The expressions are all evaluated in a list context
196before the line is processed, so a single list expression could produce
197multiple list elements. The expressions may be spread out to more than
198one line if enclosed in braces. If so, the opening brace must be the first
199token on the first line. If an expression evaluates to a number with a
200decimal part, and if the corresponding picture specifies that the decimal
201part should appear in the output (that is, any picture except multiple \*(L"#\*(R"
202characters \fBwithout\fR an embedded \*(L".\*(R"), the character used for the decimal
203point is \fBalways\fR determined by the current \s-1LC_NUMERIC\s0 locale. This
204means that, if, for example, the run-time environment happens to specify a
205German locale, \*(L",\*(R" will be used instead of the default \*(L".\*(R". See
206perllocale and \*(L"\s-1WARNINGS\s0\*(R" for more information.
207.PP
208Picture fields that begin with ^ rather than @ are treated specially.
209With a # field, the field is blanked out if the value is undefined. For
210other field types, the caret enables a kind of fill mode. Instead of an
211arbitrary expression, the value supplied must be a scalar variable name
212that contains a text string. Perl puts as much text as it can into the
213field, and then chops off the front of the string so that the next time
214the variable is referenced, more of the text can be printed. (Yes, this
215means that the variable itself is altered during execution of the \fIwrite()\fR
216call, and is not returned.) Normally you would use a sequence of fields
217in a vertical stack to print out a block of text. You might wish to end
218the final field with the text \*(L"...\*(R", which will appear in the output if
219the text was too long to appear in its entirety. You can change which
220characters are legal to break on by changing the variable \f(CW$:\fR (that's
221\&\f(CW$FORMAT_LINE_BREAK_CHARACTERS\fR if you're using the English module) to a
222list of the desired characters.
223.PP
224Using caret fields can produce variable length records. If the text
225to be formatted is short, you can suppress blank lines by putting a
226\&\*(L"~\*(R" (tilde) character anywhere in the line. The tilde will be translated
227to a space upon output. If you put a second tilde contiguous to the
228first, the line will be repeated until all the fields on the line are
229exhausted. (If you use a field of the at variety, the expression you
230supply had better not give the same value every time forever!)
231.PP
232Top-of-form processing is by default handled by a format with the
233same name as the current filehandle with \*(L"_TOP\*(R" concatenated to it.
234It's triggered at the top of each page. See \*(L"write\*(R" in perlfunc.
235.PP
236Examples:
237.PP
238.Vb 10
239\& # a report on the /etc/passwd file
240\& format STDOUT_TOP =
241\& Passwd File
242\& Name Login Office Uid Gid Home
243\& ------------------------------------------------------------------
244\& .
245\& format STDOUT =
246\& @<<<<<<<<<<<<<<<<<< @||||||| @<<<<<<@>>>> @>>>> @<<<<<<<<<<<<<<<<<
247\& $name, $login, $office,$uid,$gid, $home
248\& .
249.Ve
250.PP
251.Vb 29
252\& # a report from a bug report form
253\& format STDOUT_TOP =
254\& Bug Reports
255\& @<<<<<<<<<<<<<<<<<<<<<<< @||| @>>>>>>>>>>>>>>>>>>>>>>>
256\& $system, $%, $date
257\& ------------------------------------------------------------------
258\& .
259\& format STDOUT =
260\& Subject: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
261\& $subject
262\& Index: @<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
263\& $index, $description
264\& Priority: @<<<<<<<<<< Date: @<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
265\& $priority, $date, $description
266\& From: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
267\& $from, $description
268\& Assigned to: @<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
269\& $programmer, $description
270\& ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
271\& $description
272\& ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
273\& $description
274\& ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
275\& $description
276\& ~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
277\& $description
278\& ~ ^<<<<<<<<<<<<<<<<<<<<<<<...
279\& $description
280\& .
281.Ve
282.PP
283It is possible to intermix \fIprint()\fRs with \fIwrite()\fRs on the same output
284channel, but you'll have to handle \f(CW\*(C`$\-\*(C'\fR (\f(CW$FORMAT_LINES_LEFT\fR)
285yourself.
286.Sh "Format Variables"
287.IX Subsection "Format Variables"
288The current format name is stored in the variable \f(CW$~\fR (\f(CW$FORMAT_NAME\fR),
289and the current top of form format name is in \f(CW$^\fR (\f(CW$FORMAT_TOP_NAME\fR).
290The current output page number is stored in \f(CW$%\fR (\f(CW$FORMAT_PAGE_NUMBER\fR),
291and the number of lines on the page is in \f(CW$=\fR (\f(CW$FORMAT_LINES_PER_PAGE\fR).
292Whether to autoflush output on this handle is stored in \f(CW$|\fR
293(\f(CW$OUTPUT_AUTOFLUSH\fR). The string output before each top of page (except
294the first) is stored in \f(CW$^L\fR (\f(CW$FORMAT_FORMFEED\fR). These variables are
295set on a per-filehandle basis, so you'll need to \fIselect()\fR into a different
296one to affect them:
297.PP
298.Vb 4
299\& select((select(OUTF),
300\& $~ = "My_Other_Format",
301\& $^ = "My_Top_Format"
302\& )[0]);
303.Ve
304.PP
305Pretty ugly, eh? It's a common idiom though, so don't be too surprised
306when you see it. You can at least use a temporary variable to hold
307the previous filehandle: (this is a much better approach in general,
308because not only does legibility improve, you now have intermediary
309stage in the expression to single-step the debugger through):
310.PP
311.Vb 4
312\& $ofh = select(OUTF);
313\& $~ = "My_Other_Format";
314\& $^ = "My_Top_Format";
315\& select($ofh);
316.Ve
317.PP
318If you use the English module, you can even read the variable names:
319.PP
320.Vb 5
321\& use English '-no_match_vars';
322\& $ofh = select(OUTF);
323\& $FORMAT_NAME = "My_Other_Format";
324\& $FORMAT_TOP_NAME = "My_Top_Format";
325\& select($ofh);
326.Ve
327.PP
328But you still have those funny \fIselect()\fRs. So just use the FileHandle
329module. Now, you can access these special variables using lowercase
330method names instead:
331.PP
332.Vb 3
333\& use FileHandle;
334\& format_name OUTF "My_Other_Format";
335\& format_top_name OUTF "My_Top_Format";
336.Ve
337.PP
338Much better!
339.SH "NOTES"
340.IX Header "NOTES"
341Because the values line may contain arbitrary expressions (for at fields,
342not caret fields), you can farm out more sophisticated processing
343to other functions, like \fIsprintf()\fR or one of your own. For example:
344.PP
345.Vb 4
346\& format Ident =
347\& @<<<<<<<<<<<<<<<
348\& &commify($n)
349\& .
350.Ve
351.PP
352To get a real at or caret into the field, do this:
353.PP
354.Vb 4
355\& format Ident =
356\& I have an @ here.
357\& "@"
358\& .
359.Ve
360.PP
361To center a whole line of text, do something like this:
362.PP
363.Vb 4
364\& format Ident =
365\& @|||||||||||||||||||||||||||||||||||||||||||||||
366\& "Some text line"
367\& .
368.Ve
369.PP
370There is no builtin way to say \*(L"float this to the right hand side
371of the page, however wide it is.\*(R" You have to specify where it goes.
372The truly desperate can generate their own format on the fly, based
373on the current number of columns, and then \fIeval()\fR it:
374.PP
375.Vb 9
376\& $format = "format STDOUT = \en"
377\& . '^' . '<' x $cols . "\en"
378\& . '$entry' . "\en"
379\& . "\et^" . "<" x ($cols-8) . "~~\en"
380\& . '$entry' . "\en"
381\& . ".\en";
382\& print $format if $Debugging;
383\& eval $format;
384\& die $@ if $@;
385.Ve
386.PP
387Which would generate a format looking something like this:
388.PP
389.Vb 6
390\& format STDOUT =
391\& ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
392\& $entry
393\& ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
394\& $entry
395\& .
396.Ve
397.PP
398Here's a little program that's somewhat like \fIfmt\fR\|(1):
399.PP
400.Vb 3
401\& format =
402\& ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
403\& $_
404.Ve
405.PP
406.Vb 1
407\& .
408.Ve
409.PP
410.Vb 5
411\& $/ = '';
412\& while (<>) {
413\& s/\es*\en\es*/ /g;
414\& write;
415\& }
416.Ve
417.Sh "Footers"
418.IX Subsection "Footers"
419While \f(CW$FORMAT_TOP_NAME\fR contains the name of the current header format,
420there is no corresponding mechanism to automatically do the same thing
421for a footer. Not knowing how big a format is going to be until you
422evaluate it is one of the major problems. It's on the \s-1TODO\s0 list.
423.PP
424Here's one strategy: If you have a fixed-size footer, you can get footers
425by checking \f(CW$FORMAT_LINES_LEFT\fR before each \fIwrite()\fR and print the footer
426yourself if necessary.
427.PP
428Here's another strategy: Open a pipe to yourself, using \f(CW\*(C`open(MYSELF, "|\-")\*(C'\fR
429(see \*(L"\fIopen()\fR\*(R" in perlfunc) and always \fIwrite()\fR to \s-1MYSELF\s0 instead of \s-1STDOUT\s0.
430Have your child process massage its \s-1STDIN\s0 to rearrange headers and footers
431however you like. Not very convenient, but doable.
432.Sh "Accessing Formatting Internals"
433.IX Subsection "Accessing Formatting Internals"
434For low-level access to the formatting mechanism. you may use \fIformline()\fR
435and access \f(CW$^A\fR (the \f(CW$ACCUMULATOR\fR variable) directly.
436.PP
437For example:
438.PP
439.Vb 3
440\& $str = formline <<'END', 1,2,3;
441\& @<<< @||| @>>>
442\& END
443.Ve
444.PP
445.Vb 1
446\& print "Wow, I just stored `$^A' in the accumulator!\en";
447.Ve
448.PP
449Or to make an \fIswrite()\fR subroutine, which is to \fIwrite()\fR what \fIsprintf()\fR
450is to \fIprintf()\fR, do this:
451.PP
452.Vb 8
453\& use Carp;
454\& sub swrite {
455\& croak "usage: swrite PICTURE ARGS" unless @_;
456\& my $format = shift;
457\& $^A = "";
458\& formline($format,@_);
459\& return $^A;
460\& }
461.Ve
462.PP
463.Vb 5
464\& $string = swrite(<<'END', 1, 2, 3);
465\& Check me out
466\& @<<< @||| @>>>
467\& END
468\& print $string;
469.Ve
470.SH "WARNINGS"
471.IX Header "WARNINGS"
472The lone dot that ends a format can also prematurely end a mail
473message passing through a misconfigured Internet mailer (and based on
474experience, such misconfiguration is the rule, not the exception). So
475when sending format code through mail, you should indent it so that
476the format-ending dot is not on the left margin; this will prevent
477\&\s-1SMTP\s0 cutoff.
478.PP
479Lexical variables (declared with \*(L"my\*(R") are not visible within a
480format unless the format is declared within the scope of the lexical
481variable. (They weren't visible at all before version 5.001.)
482.PP
483Formats are the only part of Perl that unconditionally use information
484from a program's locale; if a program's environment specifies an
485\&\s-1LC_NUMERIC\s0 locale, it is always used to specify the decimal point
486character in formatted output. Perl ignores all other aspects of locale
487handling unless the \f(CW\*(C`use locale\*(C'\fR pragma is in effect. Formatted output
488cannot be controlled by \f(CW\*(C`use locale\*(C'\fR because the pragma is tied to the
489block structure of the program, and, for historical reasons, formats
490exist outside that block structure. See perllocale for further
491discussion of locale handling.
492.PP
493Inside of an expression, the whitespace characters \en, \et and \ef are
494considered to be equivalent to a single space. Thus, you could think
495of this filter being applied to each value in the format:
496.PP
497.Vb 1
498\& $value =~ tr/\en\et\ef/ /;
499.Ve
500.PP
501The remaining whitespace character, \er, forces the printing of a new
502line if allowed by the picture line.