Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / Tie::File.3
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 "Tie::File 3"
132.TH Tie::File 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134Tie::File \- Access the lines of a disk file via a Perl array
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 1
138\& # This file documents Tie::File version 0.93
139.Ve
140.PP
141.Vb 1
142\& tie @array, 'Tie::File', filename or die ...;
143.Ve
144.PP
145.Vb 2
146\& $array[13] = 'blah'; # line 13 of the file is now 'blah'
147\& print $array[42]; # display line 42 of the file
148.Ve
149.PP
150.Vb 2
151\& $n_recs = @array; # how many records are in the file?
152\& $#array -= 2; # chop two records off the end
153.Ve
154.PP
155.Vb 3
156\& for (@array) {
157\& s/PERL/Perl/g; # Replace PERL with Perl everywhere in the file
158\& }
159.Ve
160.PP
161.Vb 2
162\& # These are just like regular push, pop, unshift, shift, and splice
163\& # Except that they modify the file in the way you would expect
164.Ve
165.PP
166.Vb 5
167\& push @array, new recs...;
168\& my $r1 = pop @array;
169\& unshift @array, new recs...;
170\& my $r1 = shift @array;
171\& @old_recs = splice @array, 3, 7, new recs...;
172.Ve
173.PP
174.Vb 1
175\& untie @array; # all finished
176.Ve
177.SH "DESCRIPTION"
178.IX Header "DESCRIPTION"
179\&\f(CW\*(C`Tie::File\*(C'\fR represents a regular text file as a Perl array. Each
180element in the array corresponds to a record in the file. The first
181line of the file is element 0 of the array; the second line is element
1821, and so on.
183.PP
184The file is \fInot\fR loaded into memory, so this will work even for
185gigantic files.
186.PP
187Changes to the array are reflected in the file immediately.
188.PP
189Lazy people and beginners may now stop reading the manual.
190.ie n .Sh """recsep"""
191.el .Sh "\f(CWrecsep\fP"
192.IX Subsection "recsep"
193What is a 'record'? By default, the meaning is the same as for the
194\&\f(CW\*(C`<...>\*(C'\fR operator: It's a string terminated by \f(CW$/\fR, which is
195probably \f(CW"\en"\fR. (Minor exception: on dos and Win32 systems, a
196\&'record' is a string terminated by \f(CW"\er\en"\fR.) You may change the
197definition of \*(L"record\*(R" by supplying the \f(CW\*(C`recsep\*(C'\fR option in the \f(CW\*(C`tie\*(C'\fR
198call:
199.PP
200.Vb 1
201\& tie @array, 'Tie::File', $file, recsep => 'es';
202.Ve
203.PP
204This says that records are delimited by the string \f(CW\*(C`es\*(C'\fR. If the file
205contained the following data:
206.PP
207.Vb 1
208\& Curse these pesky flies!\en
209.Ve
210.PP
211then the \f(CW@array\fR would appear to have four elements:
212.PP
213.Vb 4
214\& "Curse th"
215\& "e p"
216\& "ky fli"
217\& "!\en"
218.Ve
219.PP
220An undefined value is not permitted as a record separator. Perl's
221special \*(L"paragraph mode\*(R" semantics (A\*` la \f(CW\*(C`$/ = ""\*(C'\fR) are not
222emulated.
223.PP
224Records read from the tied array do not have the record separator
225string on the end; this is to allow
226.PP
227.Vb 1
228\& $array[17] .= "extra";
229.Ve
230.PP
231to work as expected.
232.PP
233(See \*(L"autochomp\*(R", below.) Records stored into the array will have
234the record separator string appended before they are written to the
235file, if they don't have one already. For example, if the record
236separator string is \f(CW"\en"\fR, then the following two lines do exactly
237the same thing:
238.PP
239.Vb 2
240\& $array[17] = "Cherry pie";
241\& $array[17] = "Cherry pie\en";
242.Ve
243.PP
244The result is that the contents of line 17 of the file will be
245replaced with \*(L"Cherry pie\*(R"; a newline character will separate line 17
246from line 18. This means that this code will do nothing:
247.PP
248.Vb 1
249\& chomp $array[17];
250.Ve
251.PP
252Because the \f(CW\*(C`chomp\*(C'\fRed value will have the separator reattached when
253it is written back to the file. There is no way to create a file
254whose trailing record separator string is missing.
255.PP
256Inserting records that \fIcontain\fR the record separator string is not
257supported by this module. It will probably produce a reasonable
258result, but what this result will be may change in a future version.
259Use 'splice' to insert records or to replace one record with several.
260.ie n .Sh """autochomp"""
261.el .Sh "\f(CWautochomp\fP"
262.IX Subsection "autochomp"
263Normally, array elements have the record separator removed, so that if
264the file contains the text
265.PP
266.Vb 3
267\& Gold
268\& Frankincense
269\& Myrrh
270.Ve
271.PP
272the tied array will appear to contain \f(CW\*(C`("Gold", "Frankincense",
273"Myrrh")\*(C'\fR. If you set \f(CW\*(C`autochomp\*(C'\fR to a false value, the record
274separator will not be removed. If the file above was tied with
275.PP
276.Vb 1
277\& tie @gifts, "Tie::File", $gifts, autochomp => 0;
278.Ve
279.PP
280then the array \f(CW@gifts\fR would appear to contain \f(CW\*(C`("Gold\en",
281"Frankincense\en", "Myrrh\en")\*(C'\fR, or (on Win32 systems) \f(CW\*(C`("Gold\er\en",
282"Frankincense\er\en", "Myrrh\er\en")\*(C'\fR.
283.ie n .Sh """mode"""
284.el .Sh "\f(CWmode\fP"
285.IX Subsection "mode"
286Normally, the specified file will be opened for read and write access,
287and will be created if it does not exist. (That is, the flags
288\&\f(CW\*(C`O_RDWR | O_CREAT\*(C'\fR are supplied in the \f(CW\*(C`open\*(C'\fR call.) If you want to
289change this, you may supply alternative flags in the \f(CW\*(C`mode\*(C'\fR option.
290See Fcntl for a listing of available flags.
291For example:
292.PP
293.Vb 3
294\& # open the file if it exists, but fail if it does not exist
295\& use Fcntl 'O_RDWR';
296\& tie @array, 'Tie::File', $file, mode => O_RDWR;
297.Ve
298.PP
299.Vb 3
300\& # create the file if it does not exist
301\& use Fcntl 'O_RDWR', 'O_CREAT';
302\& tie @array, 'Tie::File', $file, mode => O_RDWR | O_CREAT;
303.Ve
304.PP
305.Vb 3
306\& # open an existing file in read-only mode
307\& use Fcntl 'O_RDONLY';
308\& tie @array, 'Tie::File', $file, mode => O_RDONLY;
309.Ve
310.PP
311Opening the data file in write-only or append mode is not supported.
312.ie n .Sh """memory"""
313.el .Sh "\f(CWmemory\fP"
314.IX Subsection "memory"
315This is an upper limit on the amount of memory that \f(CW\*(C`Tie::File\*(C'\fR will
316consume at any time while managing the file. This is used for two
317things: managing the \fIread cache\fR and managing the \fIdeferred write
318buffer\fR.
319.PP
320Records read in from the file are cached, to avoid having to re-read
321them repeatedly. If you read the same record twice, the first time it
322will be stored in memory, and the second time it will be fetched from
323the \fIread cache\fR. The amount of data in the read cache will not
324exceed the value you specified for \f(CW\*(C`memory\*(C'\fR. If \f(CW\*(C`Tie::File\*(C'\fR wants
325to cache a new record, but the read cache is full, it will make room
326by expiring the least-recently visited records from the read cache.
327.PP
328The default memory limit is 2Mib. You can adjust the maximum read
329cache size by supplying the \f(CW\*(C`memory\*(C'\fR option. The argument is the
330desired cache size, in bytes.
331.PP
332.Vb 2
333\& # I have a lot of memory, so use a large cache to speed up access
334\& tie @array, 'Tie::File', $file, memory => 20_000_000;
335.Ve
336.PP
337Setting the memory limit to 0 will inhibit caching; records will be
338fetched from disk every time you examine them.
339.PP
340The \f(CW\*(C`memory\*(C'\fR value is not an absolute or exact limit on the memory
341used. \f(CW\*(C`Tie::File\*(C'\fR objects contains some structures besides the read
342cache and the deferred write buffer, whose sizes are not charged
343against \f(CW\*(C`memory\*(C'\fR.
344.ie n .Sh """dw_size"""
345.el .Sh "\f(CWdw_size\fP"
346.IX Subsection "dw_size"
347(This is an advanced feature. Skip this section on first reading.)
348.PP
349If you use deferred writing (See \*(L"Deferred Writing\*(R", below) then
350data you write into the array will not be written directly to the
351file; instead, it will be saved in the \fIdeferred write buffer\fR to be
352written out later. Data in the deferred write buffer is also charged
353against the memory limit you set with the \f(CW\*(C`memory\*(C'\fR option.
354.PP
355You may set the \f(CW\*(C`dw_size\*(C'\fR option to limit the amount of data that can
356be saved in the deferred write buffer. This limit may not exceed the
357total memory limit. For example, if you set \f(CW\*(C`dw_size\*(C'\fR to 1000 and
358\&\f(CW\*(C`memory\*(C'\fR to 2500, that means that no more than 1000 bytes of deferred
359writes will be saved up. The space available for the read cache will
360vary, but it will always be at least 1500 bytes (if the deferred write
361buffer is full) and it could grow as large as 2500 bytes (if the
362deferred write buffer is empty.)
363.PP
364If you don't specify a \f(CW\*(C`dw_size\*(C'\fR, it defaults to the entire memory
365limit.
366.Sh "Option Format"
367.IX Subsection "Option Format"
368\&\f(CW\*(C`\-mode\*(C'\fR is a synonym for \f(CW\*(C`mode\*(C'\fR. \f(CW\*(C`\-recsep\*(C'\fR is a synonym for
369\&\f(CW\*(C`recsep\*(C'\fR. \f(CW\*(C`\-memory\*(C'\fR is a synonym for \f(CW\*(C`memory\*(C'\fR. You get the
370idea.
371.SH "Public Methods"
372.IX Header "Public Methods"
373The \f(CW\*(C`tie\*(C'\fR call returns an object, say \f(CW$o\fR. You may call
374.PP
375.Vb 2
376\& $rec = $o->FETCH($n);
377\& $o->STORE($n, $rec);
378.Ve
379.PP
380to fetch or store the record at line \f(CW$n\fR, respectively; similarly
381the other tied array methods. (See perltie for details.) You may
382also call the following methods on this object:
383.ie n .Sh """flock"""
384.el .Sh "\f(CWflock\fP"
385.IX Subsection "flock"
386.Vb 1
387\& $o->flock(MODE)
388.Ve
389.PP
390will lock the tied file. \f(CW\*(C`MODE\*(C'\fR has the same meaning as the second
391argument to the Perl built-in \f(CW\*(C`flock\*(C'\fR function; for example
392\&\f(CW\*(C`LOCK_SH\*(C'\fR or \f(CW\*(C`LOCK_EX | LOCK_NB\*(C'\fR. (These constants are provided by
393the \f(CW\*(C`use Fcntl ':flock'\*(C'\fR declaration.)
394.PP
395\&\f(CW\*(C`MODE\*(C'\fR is optional; the default is \f(CW\*(C`LOCK_EX\*(C'\fR.
396.PP
397\&\f(CW\*(C`Tie::File\*(C'\fR promises that the following sequence of operations will
398be safe:
399.PP
400.Vb 2
401\& my $o = tie @array, "Tie::File", $filename;
402\& $o->flock;
403.Ve
404.PP
405In particular, \f(CW\*(C`Tie::File\*(C'\fR will \fInot\fR read or write the file during
406the \f(CW\*(C`tie\*(C'\fR call. (Exception: Using \f(CW\*(C`mode => O_TRUNC\*(C'\fR will, of
407course, erase the file during the \f(CW\*(C`tie\*(C'\fR call. If you want to do this
408safely, then open the file without \f(CW\*(C`O_TRUNC\*(C'\fR, lock the file, and use
409\&\f(CW\*(C`@array = ()\*(C'\fR.)
410.PP
411The best way to unlock a file is to discard the object and untie the
412array. It is probably unsafe to unlock the file without also untying
413it, because if you do, changes may remain unwritten inside the object.
414That is why there is no shortcut for unlocking. If you really want to
415unlock the file prematurely, you know what to do; if you don't know
416what to do, then don't do it.
417.PP
418All the usual warnings about file locking apply here. In particular,
419note that file locking in Perl is \fBadvisory\fR, which means that
420holding a lock will not prevent anyone else from reading, writing, or
421erasing the file; it only prevents them from getting another lock at
422the same time. Locks are analogous to green traffic lights: If you
423have a green light, that does not prevent the idiot coming the other
424way from plowing into you sideways; it merely guarantees to you that
425the idiot does not also have a green light at the same time.
426.ie n .Sh """autochomp"""
427.el .Sh "\f(CWautochomp\fP"
428.IX Subsection "autochomp"
429.Vb 2
430\& my $old_value = $o->autochomp(0); # disable autochomp option
431\& my $old_value = $o->autochomp(1); # enable autochomp option
432.Ve
433.PP
434.Vb 1
435\& my $ac = $o->autochomp(); # recover current value
436.Ve
437.PP
438See \*(L"autochomp\*(R", above.
439.ie n .Sh """defer""\fP, \f(CW""flush""\fP, \f(CW""discard""\fP, and \f(CW""autodefer"""
440.el .Sh "\f(CWdefer\fP, \f(CWflush\fP, \f(CWdiscard\fP, and \f(CWautodefer\fP"
441.IX Subsection "defer, flush, discard, and autodefer"
442See \*(L"Deferred Writing\*(R", below.
443.SH "Tying to an already-opened filehandle"
444.IX Header "Tying to an already-opened filehandle"
445If \f(CW$fh\fR is a filehandle, such as is returned by \f(CW\*(C`IO::File\*(C'\fR or one
446of the other \f(CW\*(C`IO\*(C'\fR modules, you may use:
447.PP
448.Vb 1
449\& tie @array, 'Tie::File', $fh, ...;
450.Ve
451.PP
452Similarly if you opened that handle \f(CW\*(C`FH\*(C'\fR with regular \f(CW\*(C`open\*(C'\fR or
453\&\f(CW\*(C`sysopen\*(C'\fR, you may use:
454.PP
455.Vb 1
456\& tie @array, 'Tie::File', \e*FH, ...;
457.Ve
458.PP
459Handles that were opened write-only won't work. Handles that were
460opened read-only will work as long as you don't try to modify the
461array. Handles must be attached to seekable sources of data\-\-\-that
462means no pipes or sockets. If \f(CW\*(C`Tie::File\*(C'\fR can detect that you
463supplied a non-seekable handle, the \f(CW\*(C`tie\*(C'\fR call will throw an
464exception. (On Unix systems, it can detect this.)
465.SH "Deferred Writing"
466.IX Header "Deferred Writing"
467(This is an advanced feature. Skip this section on first reading.)
468.PP
469Normally, modifying a \f(CW\*(C`Tie::File\*(C'\fR array writes to the underlying file
470immediately. Every assignment like \f(CW\*(C`$a[3] = ...\*(C'\fR rewrites as much of
471the file as is necessary; typically, everything from line 3 through
472the end will need to be rewritten. This is the simplest and most
473transparent behavior. Performance even for large files is reasonably
474good.
475.PP
476However, under some circumstances, this behavior may be excessively
477slow. For example, suppose you have a million-record file, and you
478want to do:
479.PP
480.Vb 3
481\& for (@FILE) {
482\& $_ = "> $_";
483\& }
484.Ve
485.PP
486The first time through the loop, you will rewrite the entire file,
487from line 0 through the end. The second time through the loop, you
488will rewrite the entire file from line 1 through the end. The third
489time through the loop, you will rewrite the entire file from line 2 to
490the end. And so on.
491.PP
492If the performance in such cases is unacceptable, you may defer the
493actual writing, and then have it done all at once. The following loop
494will perform much better for large files:
495.PP
496.Vb 5
497\& (tied @a)->defer;
498\& for (@a) {
499\& $_ = "> $_";
500\& }
501\& (tied @a)->flush;
502.Ve
503.PP
504If \f(CW\*(C`Tie::File\*(C'\fR's memory limit is large enough, all the writing will
505done in memory. Then, when you call \f(CW\*(C`\->flush\*(C'\fR, the entire file
506will be rewritten in a single pass.
507.PP
508(Actually, the preceding discussion is something of a fib. You don't
509need to enable deferred writing to get good performance for this
510common case, because \f(CW\*(C`Tie::File\*(C'\fR will do it for you automatically
511unless you specifically tell it not to. See \*(L"autodeferring\*(R",
512below.)
513.PP
514Calling \f(CW\*(C`\->flush\*(C'\fR returns the array to immediate-write mode. If
515you wish to discard the deferred writes, you may call \f(CW\*(C`\->discard\*(C'\fR
516instead of \f(CW\*(C`\->flush\*(C'\fR. Note that in some cases, some of the data
517will have been written already, and it will be too late for
518\&\f(CW\*(C`\->discard\*(C'\fR to discard all the changes. Support for
519\&\f(CW\*(C`\->discard\*(C'\fR may be withdrawn in a future version of \f(CW\*(C`Tie::File\*(C'\fR.
520.PP
521Deferred writes are cached in memory up to the limit specified by the
522\&\f(CW\*(C`dw_size\*(C'\fR option (see above). If the deferred-write buffer is full
523and you try to write still more deferred data, the buffer will be
524flushed. All buffered data will be written immediately, the buffer
525will be emptied, and the now-empty space will be used for future
526deferred writes.
527.PP
528If the deferred-write buffer isn't yet full, but the total size of the
529buffer and the read cache would exceed the \f(CW\*(C`memory\*(C'\fR limit, the oldest
530records will be expired from the read cache until the total size is
531under the limit.
532.PP
533\&\f(CW\*(C`push\*(C'\fR, \f(CW\*(C`pop\*(C'\fR, \f(CW\*(C`shift\*(C'\fR, \f(CW\*(C`unshift\*(C'\fR, and \f(CW\*(C`splice\*(C'\fR cannot be
534deferred. When you perform one of these operations, any deferred data
535is written to the file and the operation is performed immediately.
536This may change in a future version.
537.PP
538If you resize the array with deferred writing enabled, the file will
539be resized immediately, but deferred records will not be written.
540This has a surprising consequence: \f(CW\*(C`@a = (...)\*(C'\fR erases the file
541immediately, but the writing of the actual data is deferred. This
542might be a bug. If it is a bug, it will be fixed in a future version.
543.Sh "Autodeferring"
544.IX Subsection "Autodeferring"
545\&\f(CW\*(C`Tie::File\*(C'\fR tries to guess when deferred writing might be helpful,
546and to turn it on and off automatically.
547.PP
548.Vb 3
549\& for (@a) {
550\& $_ = "> $_";
551\& }
552.Ve
553.PP
554In this example, only the first two assignments will be done
555immediately; after this, all the changes to the file will be deferred
556up to the user-specified memory limit.
557.PP
558You should usually be able to ignore this and just use the module
559without thinking about deferring. However, special applications may
560require fine control over which writes are deferred, or may require
561that all writes be immediate. To disable the autodeferment feature,
562use
563.PP
564.Vb 1
565\& (tied @o)->autodefer(0);
566.Ve
567.PP
568or
569.PP
570.Vb 1
571\& tie @array, 'Tie::File', $file, autodefer => 0;
572.Ve
573.PP
574Similarly, \f(CW\*(C`\->autodefer(1)\*(C'\fR re-enables autodeferment, and
575\&\f(CW\*(C`\->autodefer()\*(C'\fR recovers the current value of the autodefer setting.
576.SH "CAVEATS"
577.IX Header "CAVEATS"
578(That's Latin for 'warnings'.)
579.IP "\(bu" 4
580This is \s-1BETA\s0 \s-1RELEASE\s0 \s-1SOFTWARE\s0. It may have bugs. See the discussion
581below about the (lack of any) warranty.
582.Sp
583In particular, this means that the interface may change in
584incompatible ways from one version to the next, without warning. That
585has happened at least once already. The interface will freeze before
586Perl 5.8 is released, probably sometime in April 2002.
587.IP "\(bu" 4
588Reasonable effort was made to make this module efficient. Nevertheless,
589changing the size of a record in the middle of a large file will
590always be fairly slow, because everything after the new record must be
591moved.
592.IP "\(bu" 4
593The behavior of tied arrays is not precisely the same as for regular
594arrays. For example:
595.Sp
596.Vb 2
597\& # This DOES print "How unusual!"
598\& undef $a[10]; print "How unusual!\en" if defined $a[10];
599.Ve
600.Sp
601\&\f(CW\*(C`undef\*(C'\fR\-ing a \f(CW\*(C`Tie::File\*(C'\fR array element just blanks out the
602corresponding record in the file. When you read it back again, you'll
603get the empty string, so the supposedly\-\f(CW\*(C`undef\*(C'\fR'ed value will be
604defined. Similarly, if you have \f(CW\*(C`autochomp\*(C'\fR disabled, then
605.Sp
606.Vb 3
607\& # This DOES print "How unusual!" if 'autochomp' is disabled
608\& undef $a[10];
609\& print "How unusual!\en" if $a[10];
610.Ve
611.Sp
612Because when \f(CW\*(C`autochomp\*(C'\fR is disabled, \f(CW$a[10]\fR will read back as
613\&\f(CW"\en"\fR (or whatever the record separator string is.)
614.Sp
615There are other minor differences, particularly regarding \f(CW\*(C`exists\*(C'\fR
616and \f(CW\*(C`delete\*(C'\fR, but in general, the correspondence is extremely close.
617.IP "\(bu" 4
618Not quite every effort was made to make this module as efficient as
619possible. \f(CW\*(C`FETCHSIZE\*(C'\fR should use binary search instead of linear
620search.
621.Sp
622The performance of the \f(CW\*(C`flush\*(C'\fR method could be improved. At present,
623it still rewrites the tail of the file once for each block of
624contiguous lines to be changed. In the typical case, this will result
625in only one rewrite, but in peculiar cases it might be bad. It should
626be possible to perform \fIall\fR deferred writing with a single rewrite.
627.Sp
628Profiling suggests that these defects are probably minor; in any
629event, they will be fixed in a future version of the module.
630.IP "\(bu" 4
631I have supposed that since this module is concerned with file I/O,
632almost all normal use of it will be heavily I/O bound. This means
633that the time to maintain complicated data structures inside the
634module will be dominated by the time to actually perform the I/O.
635When there was an opportunity to spend \s-1CPU\s0 time to avoid doing I/O, I
636tried to take it.
637.IP "\(bu" 4
638You might be tempted to think that deferred writing is like
639transactions, with \f(CW\*(C`flush\*(C'\fR as \f(CW\*(C`commit\*(C'\fR and \f(CW\*(C`discard\*(C'\fR as
640\&\f(CW\*(C`rollback\*(C'\fR, but it isn't, so don't.
641.SH "SUBCLASSING"
642.IX Header "SUBCLASSING"
643This version promises absolutely nothing about the internals, which
644may change without notice. A future version of the module will have a
645well-defined and stable subclassing \s-1API\s0.
646.ie n .SH "WHAT ABOUT ""DB_File""?"
647.el .SH "WHAT ABOUT \f(CWDB_File\fP?"
648.IX Header "WHAT ABOUT DB_File?"
649People sometimes point out that DB_File will do something similar,
650and ask why \f(CW\*(C`Tie::File\*(C'\fR module is necessary.
651.PP
652There are a number of reasons that you might prefer \f(CW\*(C`Tie::File\*(C'\fR.
653A list is available at \f(CW\*(C`http://perl.plover.com/TieFile/why\-not\-DB_File\*(C'\fR.
654.SH "AUTHOR"
655.IX Header "AUTHOR"
656Mark Jason Dominus
657.PP
658To contact the author, send email to: \f(CW\*(C`mjd\-perl\-tiefile+@plover.com\*(C'\fR
659.PP
660To receive an announcement whenever a new version of this module is
661released, send a blank email message to
662\&\f(CW\*(C`mjd\-perl\-tiefile\-subscribe@plover.com\*(C'\fR.
663.PP
664The most recent version of this module, including documentation and
665any news of importance, will be available at
666.PP
667.Vb 1
668\& http://perl.plover.com/TieFile/
669.Ve
670.SH "LICENSE"
671.IX Header "LICENSE"
672\&\f(CW\*(C`Tie::File\*(C'\fR version 0.93 is copyright (C) 2002 Mark Jason Dominus.
673.PP
674This library is free software; you may redistribute it and/or modify
675it under the same terms as Perl itself.
676.PP
677These terms are your choice of any of (1) the Perl Artistic Licence,
678or (2) version 2 of the \s-1GNU\s0 General Public License as published by the
679Free Software Foundation, or (3) any later version of the \s-1GNU\s0 General
680Public License.
681.PP
682This library is distributed in the hope that it will be useful,
683but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of
684\&\s-1MERCHANTABILITY\s0 or \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0. See the
685\&\s-1GNU\s0 General Public License for more details.
686.PP
687You should have received a copy of the \s-1GNU\s0 General Public License
688along with this library program; it should be in the file \f(CW\*(C`COPYING\*(C'\fR.
689If not, write to the Free Software Foundation, Inc., 59 Temple Place,
690Suite 330, Boston, \s-1MA\s0 02111 \s-1USA\s0
691.PP
692For licensing inquiries, contact the author at:
693.PP
694.Vb 3
695\& Mark Jason Dominus
696\& 255 S. Warnock St.
697\& Philadelphia, PA 19107
698.Ve
699.SH "WARRANTY"
700.IX Header "WARRANTY"
701\&\f(CW\*(C`Tie::File\*(C'\fR version 0.93 comes with \s-1ABSOLUTELY\s0 \s-1NO\s0 \s-1WARRANTY\s0.
702For details, see the license.
703.SH "THANKS"
704.IX Header "THANKS"
705Gigantic thanks to Jarkko Hietaniemi, for agreeing to put this in the
706core when I hadn't written it yet, and for generally being helpful,
707supportive, and competent. (Usually the rule is \*(L"choose any one.\*(R")
708Also big thanks to Abhijit Menon-Sen for all of the same things.
709.PP
710Special thanks to Craig Berry and Peter Prymmer (for \s-1VMS\s0 portability
711help), Randy Kobes (for Win32 portability help), Clinton Pierce and
712Autrijus Tang (for heroic eleventh-hour Win32 testing above and beyond
713the call of duty), Michael G Schwern (for testing advice), and the
714rest of the \s-1CPAN\s0 testers (for testing generally).
715.PP
716Additional thanks to:
717Edward Avis /
718Gerrit Haase /
719Nikola Knezevic /
720Nick Ing-Simmons /
721Tassilo von Parseval /
722H. Dieter Pearcey /
723Slaven Rezic /
724Peter Scott /
725Peter Somu /
726Autrijus Tang (again) /
727Tels /
728Juerd Wallboer
729.SH "TODO"
730.IX Header "TODO"
731More tests. (The cache and heap modules need more unit tests.)
732.PP
733Improve \s-1SPLICE\s0 algorithm to use deferred writing machinery.
734.PP
735Cleverer strategy for flushing deferred writes.
736.PP
737More tests. (Stuff I didn't think of yet.)
738.PP
739Paragraph mode?
740.PP
741Fixed-length mode. Leave-blanks mode.
742.PP
743Maybe an autolocking mode?
744.PP
745Record locking with \fIfcntl()\fR? Then the module might support an undo
746log and get real transactions. What a tour de force that would be.
747.PP
748More tests.