File: perlform.html

package info (click to toggle)
perl-doc-html 5.26.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 39,400 kB
  • sloc: xml: 36; makefile: 7
file content (736 lines) | stat: -rw-r--r-- 43,280 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>perlform - perldoc.perl.org</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta http-equiv="Content-Language" content="en-gb">
  <link rel="search" type="application/opensearchdescription+xml" title="Search perldoc.perl.org" href="/static/search.xml"/>
  <link href="static/css-20100830.css" rel="stylesheet" rev="stylesheet" type="text/css" media="screen">
  <link href="static/exploreperl.css" rel="stylesheet" rev="stylesheet" type="text/css">
</head>

<body onLoad="perldoc.startup();" onPageShow="if (event.persisted) perldoc.startup();">
    <div id="page">
      
      <div id="header">
	<div id="homepage_link">
	  <a href="index.html"></a>
	</div>
	<div id="strapline">
	  Perl Programming Documentation
	</div>
	<div id="download_link" class="download">
	  <a href="http://www.perl.org/get.html">Download Perl</a>
	</div>
	<div id="explore_link" class="download">
	  <a id="explore_anchor" href="#">Explore</a>
	</div>
      </div>
      
      <div id="body">
        <div id="left_column">
          <div class="side_group">
            
	    <div class="side_panel doc_panel">
              <p>Manual</p>
              <ul>
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">History / Changes</a>
                <li><a href="index-licence.html">License</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Reference</p>
              <ul>
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Special Variables</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platform Specific</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Modules</p>
              <ul>
		<li>
		
                
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		
                  
		
		
                    <a href="index-modules-A.html">A</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-B.html">B</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-C.html">C</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-D.html">D</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-E.html">E</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-F.html">F</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-G.html">G</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-H.html">H</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-I.html">I</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-L.html">L</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-M.html">M</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-N.html">N</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-O.html">O</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-P.html">P</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-S.html">S</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-T.html">T</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-U.html">U</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-X.html">X</a>
                    
                
              </ul>
            </div>
            
	      <div class="side_panel doc_panel">
		<p>Tools</p>
		<ul>
		  <li><a href="preferences.html">Preferences</a>
		</ul>
	      </div>
            
          </div>
        </div>
        <div id="centre_column">
          <div id="content_header">
            <div id="title_bar">
              <div id="page_name">
                <h1>perlform</h1>
              </div>
              <div id="perl_version">
                Perl 5 version 26.0 documentation
              </div>
              <div class="page_links" id="page_links_top">
                <a href="#" onClick="toolbar.goToTop();return false;">Go to top</a>
		
              </div>
	      <div class="page_links" id="page_links_bottom">
		
                  <a href="#" id="page_index_toggle">Show page index</a> &bull;
		
                <a href="#" id="recent_pages_toggle">Show recent pages</a>		
	      </div>
	      <div id="search_form">
		<form action="search.html" method="GET" id="search">
		  <input type="text" name="q" id="search_box" alt="Search">
		</form>
	      </div>
            </div>
            <div id="breadcrumbs">
                
    <a href="index.html">Home</a> &gt;
    
      
        <a href="index-language.html">Language reference</a> &gt;
      
    
    perlform
  

            </div>
          </div>
          <div id="content_body">
	    <!--[if lt IE 7]>
 <div class="noscript">
   <p>
     <strong>It looks like you're using Internet Explorer 6. This is a very old
     browser which does not offer full support for modern websites.</strong>
   </p>
   <p>
     Unfortunately this means that this website will not work on
     your computer.
   </p>
   <p>
     Don't miss out though! To view the site (and get a better experience from
     many other websites), simply upgrade to
     <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet
Explorer 8</a>
     or download an alternative browser such as
     <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>,
     <a href="http://www.apple.com/safari/download/">Safari</a>, or
     <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
   </p>
   <p>
     All of these browsers are free. If you're using a PC at work, you may
     need to contact your IT administrator.
   </p>
 </div>
<![endif]-->
	    <noscript>
	      <div class="noscript">
	      <p>
                <strong>Please note: Many features of this site require JavaScript. You appear to have JavaScript disabled,
	        or are running a non-JavaScript capable web browser.</strong>
	      </p>
	      <p>
		To get the best experience, please enable JavaScript or download a modern web browser such as <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet Explorer 8</a>, <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>, <a href="http://www.apple.com/safari/download/">Safari</a>, or <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
              </p>
	      </div>
	    </noscript>

	    <div id="recent_pages" class="hud_container">
	      <div id="recent_pages_header" class="hud_header">
		<div id="recent_pages_close" class="hud_close"><a href="#" onClick="recentPages.hide();return false;"></a></div>
		<div id="recent_pages_title" class="hud_title"><span class="hud_span_top">Recently read</span></div>
		<div id="recent_pages_topright" class="hud_topright"></div>
	      </div>
	      <div id="recent_pages_content" class="hud_content">
	      </div>
	      <div id="recent_pages_footer" class="hud_footer">
		<div id="recent_pages_bottomleft" class="hud_bottomleft"></div>
		<div id="recent_pages_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
		<div id="recent_pages_resize" class="hud_resize"></div>
	      </div>
	    </div>
  
	    <div id="from_search"></div>
            <h1>perlform</h1>


  <!--    -->
<ul><li><a href="#NAME">NAME
  </a><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#Text-Fields">Text Fields
</a><li><a href="#Numeric-Fields">Numeric Fields
 </a><li><a href="#The-Field-%40*-for-Variable-Width-Multi-Line-Text">The Field @* for Variable-Width Multi-Line Text
</a><li><a href="#The-Field-%5e*-for-Variable-Width-One-line-at-a-time-Text">The Field ^* for Variable-Width One-line-at-a-time Text
</a><li><a href="#Specifying-Values">Specifying Values
</a><li><a href="#Using-Fill-Mode">Using Fill Mode
</a><li><a href="#Suppressing-Lines-Where-All-Fields-Are-Void">Suppressing Lines Where All Fields Are Void
</a><li><a href="#Repeating-Format-Lines">Repeating Format Lines
</a><li><a href="#Top-of-Form-Processing">Top of Form Processing
  </a><li><a href="#Format-Variables">Format Variables

</a></ul><li><a href="#NOTES">NOTES</a><ul><li><a href="#Footers">Footers
 </a><li><a href="#Accessing-Formatting-Internals">Accessing Formatting Internals
</a></ul><li><a href="#WARNINGS">WARNINGS</a></ul><a name="NAME"></a><h1>NAME
  </h1>
<p>perlform - Perl formats</p>
<a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
<p>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 <a href="perlfunc.html">perlfunc</a>.  Fortunately, the layout is
much more legible, more like BASIC's PRINT USING statement.  Think of it
as a poor man's nroff(1).
</p>
<p>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.</p>
<p>Output record formats are declared as follows:</p>
<pre class="verbatim"><ol><li>    format NAME =</li><li>    FORMLIST</li><li>    .</li></ol></pre><p>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:</p>
<dl>
<dt>1.</dt><dd>
<p>A comment, indicated by putting a '#' in the first column.</p>
</dd>
<dt>2.</dt><dd>
<p>A "picture" line giving the format for one output line.</p>
</dd>
<dt>3.</dt><dd>
<p>An argument line supplying values to plug into the previous picture line.</p>
</dd>
</dl>
<p>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:

        
   </p>
<pre class="verbatim"><ol><li>   <span class="i">@    start</span> <span class="w">of</span> <span class="w">regular</span> <span class="w">field</span></li><li>   ^    <span class="w">start</span> <span class="w">of</span> <span class="w">special</span> <span class="w">field</span></li><li>   &lt;    <span class="w">pad</span> <span class="w">character</span> for <span class="w">left</span> <span class="w">justification</span></li><li>   |    <span class="w">pad</span> <span class="w">character</span> for <span class="w">centering</span></li><li>   &gt;    <span class="w">pad</span> <span class="w">character</span> for <span class="w">right</span> <span class="w">justification</span></li><li>   <span class="c">#    pad character for a right-justified numeric field</span></li><li>   <span class="n">0</span>    <span class="w">instead</span> <span class="w">of</span> <span class="w">first</span> <span class="c">#: pad number with leading zeroes</span></li><li>   .    <span class="w">decimal</span> <span class="w">point</span> <span class="w">within</span> <span class="w">a</span> <span class="w">numeric</span> <span class="w">field</span></li><li>   ...  <span class="w">terminate</span> <span class="w">a</span> <span class="w">text</span> <span class="w">field</span><span class="cm">,</span> <span class="w">show</span> <span class="q">&quot;...&quot;</span> <span class="w">as</span> <span class="w">truncation</span> <span class="w">evidence</span></li><li>   <span class="i">@*</span>   <span class="w">variable</span> <span class="w">width</span> <span class="w">field</span> for <span class="w">a</span> <span class="w">multi</span>-<span class="w">line</span> <span class="w">value</span></li><li>   ^<span class="i">*   variable</span> <span class="w">width</span> <span class="w">field</span> for <a class="l_k" href="functions/next.html">next</a> <span class="j">line</span> <span class="w">of</span> <span class="w">a</span> <span class="w">multi</span>-<span class="w">line</span> <span class="w">value</span></li><li>   ~    <span class="w">suppress</span> <span class="w">line</span> <span class="w">with</span> <span class="w">all</span> <span class="w">fields</span> <span class="w">empty</span></li><li>   ~~   <span class="w">repeat</span> <span class="w">line</span> until <span class="w">all</span> <span class="w">fields</span> <span class="w">are</span> <span class="w">exhausted</span></li></ol></pre><p>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.</p>
<a name="Text-Fields"></a><h2>Text Fields
</h2>
<p>The length of the field is supplied by padding out the field with multiple 
"&lt;", "&gt;", 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 <a href="#Using-Fill-Mode">Using Fill Mode</a> for details.</p>
<pre class="verbatim"><ol><li>   Example:</li><li>      format STDOUT =</li><li>      @&lt;&lt;&lt;&lt;&lt;&lt;   @||||||   @&gt;&gt;&gt;&gt;&gt;&gt;</li><li>      "left",   "middle", "right"</li><li>      .</li><li>   Output:</li><li>      left      middle    right</li></ol></pre><a name="Numeric-Fields"></a><h2>Numeric Fields
 </h2>
<p>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.</p>
<pre class="verbatim"><ol><li>   Example:</li><li>      format STDOUT =</li><li>      @###   @.###   @##.###  @###   @###   ^####</li><li>       42,   3.1415,  undef,    0, 10000,   undef</li><li>      .</li><li>   Output:</li><li>        42   3.142     0.000     0   ####</li></ol></pre><a name="The-Field-%40*-for-Variable-Width-Multi-Line-Text"></a><h2>The Field @* for Variable-Width Multi-Line Text
</h2>
<p>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.</p>
<a name="The-Field-%5e*-for-Variable-Width-One-line-at-a-time-Text"></a><h2>The Field ^* for Variable-Width One-line-at-a-time Text
</h2>
<p>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>not</i> be restored.</p>
<pre class="verbatim"><ol><li>   Example:</li><li>      $text = "line 1\nline 2\nline 3";</li><li>      format STDOUT =</li><li>      Text: ^*</li><li>            $text</li><li>      ~~    ^*</li><li>            $text</li><li>      .</li><li>   Output:</li><li>      Text: line 1</li><li>            line 2</li><li>            line 3</li></ol></pre><a name="Specifying-Values"></a><h2>Specifying Values
</h2>
<p>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>without</b> an embedded "."), the character used for the decimal
point is determined by the current LC_NUMERIC locale if <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">locale</span></code>
 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
<a href="perllocale.html">perllocale</a> and <a href="#WARNINGS">WARNINGS</a> for more information.</p>
<a name="Using-Fill-Mode"></a><h2>Using Fill Mode
</h2>
<p>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
(<code class="inline">\<span class="w">r</span></code>
) to force a line break. You can change which characters are legal 
to break on by changing the variable <code class="inline"><span class="i">$:</span></code>
 (that's 
$FORMAT_LINE_BREAK_CHARACTERS if you're using the English module) to a 
list of the desired characters.</p>
<p>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.</p>
<a name="Suppressing-Lines-Where-All-Fields-Are-Void"></a><h2>Suppressing Lines Where All Fields Are Void
</h2>
<p>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.</p>
<a name="Repeating-Format-Lines"></a><h2>Repeating Format Lines
</h2>
<p>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! (<code class="inline"><a class="l_k" href="functions/shift.html">shift(@f)</a></code>
is a simple example that would work.)  Don't use a regular (at) numeric 
field in such lines, because it will never go blank.</p>
<a name="Top-of-Form-Processing"></a><h2>Top of Form Processing
  </h2>
<p>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 <a href="functions/write.html">write</a>.</p>
<p>Examples:</p>
<pre class="verbatim"><ol><li> # a report on the /etc/passwd file</li><li> format STDOUT_TOP =</li><li>                         Passwd File</li><li> Name                Login    Office   Uid   Gid Home</li><li> ------------------------------------------------------------------</li><li> .</li><li> format STDOUT =</li><li> @&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; @||||||| @&lt;&lt;&lt;&lt;&lt;&lt;@&gt;&gt;&gt;&gt; @&gt;&gt;&gt;&gt; @&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li> $name,              $login,  $office,$uid,$gid, $home</li><li> .</li><li></li><li></li><li> # a report from a bug report form</li><li> format STDOUT_TOP =</li><li>                         Bug Reports</li><li> @&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;     @|||         @&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;</li><li> $system,                      $%,         $date</li><li> ------------------------------------------------------------------</li><li> .</li><li> format STDOUT =</li><li> Subject: @&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li>          $subject</li><li> Index: @&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li>        $index,                       $description</li><li> Priority: @&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; Date: @&lt;&lt;&lt;&lt;&lt;&lt;&lt; ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li>           $priority,        $date,   $description</li><li> From: @&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li>       $from,                         $description</li><li> Assigned to: @&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li>              $programmer,            $description</li><li> ~                                    ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li>                                      $description</li><li> ~                                    ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li>                                      $description</li><li> ~                                    ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li>                                      $description</li><li> ~                                    ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li>                                      $description</li><li> ~                                    ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;...</li><li>                                      $description</li><li> .</li></ol></pre><p>It is possible to intermix print()s with write()s on the same output
channel, but you'll have to handle <code class="inline"><span class="i">$-</span></code>
 (<code class="inline"><span class="i">$FORMAT_LINES_LEFT</span></code>
)
yourself.</p>
<a name="Format-Variables"></a><h2>Format Variables

</h2>
<p>The current format name is stored in the variable <code class="inline"><span class="i">$~</span></code>
 (<code class="inline"><span class="i">$FORMAT_NAME</span></code>
),
and the current top of form format name is in <code class="inline"><span class="i">$^</span></code>
 (<code class="inline"><span class="i">$FORMAT_TOP_NAME</span></code>
).
The current output page number is stored in <code class="inline"><span class="i">$%</span></code>
 (<code class="inline"><span class="i">$FORMAT_PAGE_NUMBER</span></code>
),
and the number of lines on the page is in <code class="inline"><span class="i">$=</span></code>
 (<code class="inline"><span class="i">$FORMAT_LINES_PER_PAGE</span></code>
).
Whether to autoflush output on this handle is stored in <code class="inline"><span class="i">$|</span></code>

(<code class="inline"><span class="i">$OUTPUT_AUTOFLUSH</span></code>
).  The string output before each top of page (except
the first) is stored in <code class="inline"><span class="i">$^L</span></code>
 (<code class="inline"><span class="i">$FORMAT_FORMFEED</span></code>
).  These variables are
set on a per-filehandle basis, so you'll need to select() into a different
one to affect them:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/select.html">select</a><span class="s">(</span><span class="s">(</span><a class="l_k" href="functions/select.html">select</a><span class="s">(</span><span class="w">OUTF</span><span class="s">)</span><span class="cm">,</span></li><li>	    <span class="i">$~</span> = <span class="q">&quot;My_Other_Format&quot;</span><span class="cm">,</span></li><li>	    <span class="i">$^</span> = <span class="q">&quot;My_Top_Format&quot;</span></li><li>	   <span class="s">)</span>[<span class="n">0</span>]<span class="s">)</span><span class="sc">;</span></li></ol></pre><p>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):</p>
<pre class="verbatim"><ol><li>    <span class="i">$ofh</span> = <a class="l_k" href="functions/select.html">select</a><span class="s">(</span><span class="w">OUTF</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="i">$~</span> = <span class="q">&quot;My_Other_Format&quot;</span><span class="sc">;</span></li><li>    <span class="i">$^</span> = <span class="q">&quot;My_Top_Format&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/select.html">select</a><span class="s">(</span><span class="i">$ofh</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>If you use the English module, you can even read the variable names:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">English</span><span class="sc">;</span></li><li>    <span class="i">$ofh</span> = <a class="l_k" href="functions/select.html">select</a><span class="s">(</span><span class="w">OUTF</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="i">$FORMAT_NAME</span>     = <span class="q">&quot;My_Other_Format&quot;</span><span class="sc">;</span></li><li>    <span class="i">$FORMAT_TOP_NAME</span> = <span class="q">&quot;My_Top_Format&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/select.html">select</a><span class="s">(</span><span class="i">$ofh</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>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:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">FileHandle</span><span class="sc">;</span></li><li>    <span class="w">format_name</span>     <span class="w">OUTF</span> <span class="q">&quot;My_Other_Format&quot;</span><span class="sc">;</span></li><li>    <span class="w">format_top_name</span> <span class="w">OUTF</span> <span class="q">&quot;My_Top_Format&quot;</span><span class="sc">;</span></li></ol></pre><p>Much better!</p>
<a name="NOTES"></a><h1>NOTES</h1>
<p>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:</p>
<pre class="verbatim"><ol><li>    format Ident =</li><li>	@&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li>	&amp;commify($n)</li><li>    .</li></ol></pre><p>To get a real at or caret into the field, do this:</p>
<pre class="verbatim"><ol><li>    format Ident =</li><li>    I have an @ here.</li><li>	    "@"</li><li>    .</li></ol></pre><p>To center a whole line of text, do something like this:</p>
<pre class="verbatim"><ol><li>    format Ident =</li><li>    @|||||||||||||||||||||||||||||||||||||||||||||||</li><li>	    "Some text line"</li><li>    .</li></ol></pre><p>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:</p>
<pre class="verbatim"><ol><li>    <span class="i">$format</span>  = <span class="q">&quot;format STDOUT = \n&quot;</span></li><li>             . <span class="q">&#39;^&#39;</span> . <span class="q">&#39;&lt;&#39;</span> x <span class="i">$cols</span> . <span class="q">&quot;\n&quot;</span></li><li>             . <span class="q">&#39;$entry&#39;</span> . <span class="q">&quot;\n&quot;</span></li><li>             . <span class="q">&quot;\t^&quot;</span> . <span class="q">&quot;&lt;&quot;</span> x <span class="s">(</span><span class="i">$cols</span>-<span class="n">8</span><span class="s">)</span> . <span class="q">&quot;~~\n&quot;</span></li><li>             . <span class="q">&#39;$entry&#39;</span> . <span class="q">&quot;\n&quot;</span></li><li>             . <span class="q">&quot;.\n&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$format</span> if <span class="i">$Debugging</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="i">$format</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/die.html">die</a> <span class="i">$@</span> if <span class="i">$@</span><span class="sc">;</span></li></ol></pre><p>Which would generate a format looking something like this:</p>
<pre class="verbatim"><ol><li> format STDOUT =</li><li> ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</li><li> $entry</li><li>         ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;~~</li><li> $entry</li><li> .</li></ol></pre><p>Here's a little program that's somewhat like fmt(1):</p>
<pre class="verbatim"><ol><li> format =</li><li> ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; ~~</li><li> $_</li><li></li><li> .</li><li></li><li> $/ = '';</li><li> while (&lt;&gt;) {</li><li>     s/\s*\n\s*/ /g;</li><li>     write;</li><li> }</li></ol></pre><a name="Footers"></a><h2>Footers
 </h2>
<p>While $FORMAT_TOP_NAME contains the name of the current header format,
there is no corresponding mechanism to automatically do the same thing
for a footer.  Not knowing how big a format is going to be until you
evaluate it is one of the major problems.  It's on the TODO list.</p>
<p>Here's one strategy:  If you have a fixed-size footer, you can get footers
by checking $FORMAT_LINES_LEFT before each write() and print the footer
yourself if necessary.</p>
<p>Here's another strategy: Open a pipe to yourself, using <code class="inline"><a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">MYSELF</span><span class="cm">,</span> <span class="q">&quot;|-&quot;</span><span class="s">)</span></code>

(see <a href="functions/open.html">open</a>) 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.</p>
<a name="Accessing-Formatting-Internals"></a><h2>Accessing Formatting Internals
</h2>
<p>For low-level access to the formatting mechanism, you may use formline()
and access <code class="inline"><span class="i">$^A</span></code>
 (the $ACCUMULATOR variable) directly.</p>
<p>For example:</p>
<pre class="verbatim"><ol><li>    <span class="i">$str</span> = <a class="l_k" href="functions/formline.html">formline</a> <span class="h">&lt;&lt;&#39;END&#39;</span><span class="cm">,</span> <span class="n">1</span><span class="cm">,</span><span class="n">2</span><span class="cm">,</span><span class="n">3</span><span class="sc">;</span></li><li><span class="hh">    @&lt;&lt;&lt;  @|||  @&gt;&gt;&gt;</span></li><li><span class="hh">    END</span></li><li></li><li><span class="hh">    print &quot;Wow, I just stored &#39;$^A&#39; in the accumulator!\n&quot;;</span></li></ol></pre><p>Or to make an swrite() subroutine, which is to write() what sprintf()
is to printf(), do this:</p>
<pre class="verbatim"><ol><li>    use Carp;</li><li>    sub swrite {</li><li>	croak "usage: swrite PICTURE ARGS" unless @_;</li><li>	my $format = shift;</li><li>	$^A = "";</li><li>	formline($format,@_);</li><li>	return $^A;</li><li>    }</li><li></li><li>    $string = swrite(&lt;&lt;'END', 1, 2, 3);</li><li> Check me out</li><li> @&lt;&lt;&lt;  @|||  @&gt;&gt;&gt;</li><li> END</li><li>    print $string;</li></ol></pre><a name="WARNINGS"></a><h1>WARNINGS</h1>
<p>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 mail, you should indent it so that
the format-ending dot is not on the left margin; this will prevent
SMTP cutoff.</p>
<p>Lexical variables (declared with "my") are not visible within a
format unless the format is declared within the scope of the lexical
variable.</p>
<p>If a program's environment specifies an LC_NUMERIC locale and <code class="inline"><a class="l_k" href="functions/use.html">use</a>
<span class="w">locale</span></code>
 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 <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">locale</span></code>
 at the time when write()
is called. See <a href="perllocale.html">perllocale</a> for further discussion of locale handling.</p>
<p>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 <code class="inline">\<span class="w">r</span></code>
 when using fill mode.) This is done to avoid
misalignment when control characters "disappear" on some output media.</p>




  <div id="page_index" class="hud_container">
    <div id="page_index_header" class="hud_header">
      <div id="page_index_close" class="hud_close"><a href="#" onClick="pageIndex.hide();return false;"></a></div>
      <div id="page_index_title" class="hud_title"><span class="hud_span_top">Page index</span></div>
      <div id="page_index_topright" class="hud_topright"></div>
    </div>
    <div id="page_index_content" class="hud_content">
      <ul><li><a href="#NAME">NAME
  </a><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#Text-Fields">Text Fields
</a><li><a href="#Numeric-Fields">Numeric Fields
 </a><li><a href="#The-Field-%40*-for-Variable-Width-Multi-Line-Text">The Field @* for Variable-Width Multi-Line Text
</a><li><a href="#The-Field-%5e*-for-Variable-Width-One-line-at-a-time-Text">The Field ^* for Variable-Width One-line-at-a-time Text
</a><li><a href="#Specifying-Values">Specifying Values
</a><li><a href="#Using-Fill-Mode">Using Fill Mode
</a><li><a href="#Suppressing-Lines-Where-All-Fields-Are-Void">Suppressing Lines Where All Fields Are Void
</a><li><a href="#Repeating-Format-Lines">Repeating Format Lines
</a><li><a href="#Top-of-Form-Processing">Top of Form Processing
  </a><li><a href="#Format-Variables">Format Variables

</a></ul><li><a href="#NOTES">NOTES</a><ul><li><a href="#Footers">Footers
 </a><li><a href="#Accessing-Formatting-Internals">Accessing Formatting Internals
</a></ul><li><a href="#WARNINGS">WARNINGS</a></ul>
    </div>
    <div id="page_index_footer" class="hud_footer">
      <div id="page_index_bottomleft" class="hud_bottomleft"></div>
      <div id="page_index_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
      <div id="page_index_resize" class="hud_resize"></div>
    </div>
  </div>


	    &nbsp;
          </div>
          <div id="content_footer">
          </div>
        </div>
        <div class="clear"></div>
      </div>
      
    <div id="footer">
      <div id="footer_content">
        <div id="footer_strapline">
          perldoc.perl.org - Official documentation for the Perl programming language
        </div>
        <div id="footer_links">
          <div id="address">
            <p class="name">Contact details</p>
            <p class="address">
	      Site maintained by <a href="mailto:jj@jonallen.info">Jon Allen (JJ)</a><br>
	    </p>
            <p class="contact">
              Documentation maintained by the <a href="http://lists.cpan.org/showlist.cgi?name=perl5-porters">Perl 5 Porters</a>
            </p>
          </div>
          <ul class="f1">
            <li>Manual
              <ul class="f2">
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">Changes</a>
              </ul>
            <li>Reference
              <ul class="f2">
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Variables</a>
              </ul>
            <li>Modules
              <ul class="f2">
                <li><a href="index-modules-A.html">Modules</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
              </ul>
            <li>Misc
              <ul class="f2">
                <li><a href="index-licence.html">License</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platforms</a>
              </ul>          </ul>
          <div class="clear"></div>
        </div>
      </div>
      <div id="footer_end">
      </div>
    </div>
      
    </div>
      <script language="JavaScript" type="text/javascript" src="static/exploreperl.js"></script>
      <script language="JavaScript" src="static/combined-20100403.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
  perldoc.setPath(0);
  perldoc.pageName    = 'perlform';
  perldoc.pageAddress = 'perlform.html';
  perldoc.contentPage = 1;
  explorePerl.render();
  explorePerl.addEvents('explore_anchor');
</script>
    
  </body>
</html>