X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlfaq5.pod;h=31db204129115cf2b4b8a5da0ec9d100f0424d17;hb=af9e49b40a4cc2d6c0d5ebad7e84fb62143b24e1;hp=ab0ba26be4aedb6d05affd6e129d68be6026b736;hpb=7678ccedef3d2583c849cbd8e5a13ba36925ac4c;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlfaq5.pod b/pod/perlfaq5.pod index ab0ba26..31db204 100644 --- a/pod/perlfaq5.pod +++ b/pod/perlfaq5.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq5 - Files and Formats ($Revision: 1.35 $, $Date: 2005/01/21 12:26:11 $) +perlfaq5 - Files and Formats ($Revision: 1.38 $, $Date: 2005/10/13 19:49:13 $) =head1 DESCRIPTION @@ -8,6 +8,7 @@ This section deals with I/O and the "f" issues: filehandles, flushing, formats, and footers. =head2 How do I flush/unbuffer an output filehandle? Why must I do this? +X X X X Perl does not support truly unbuffered output (except insofar as you can C), although it @@ -61,11 +62,13 @@ or IO::Socket: $sock->autoflush(); =head2 How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? +X Use the Tie::File module, which is included in the standard distribution since Perl 5.8.0. =head2 How do I count the number of lines in a file? +X X X One fairly efficient way is to count newlines in the file. The following program uses a feature of tr///, as documented in L. @@ -82,6 +85,7 @@ proper text file, so this may report one fewer line than you expect. This assumes no funny games with newline translations. =head2 How can I use Perl's C<-i> option from within a program? +X<-i> X C<-i> sets the value of Perl's C<$^I> variable, which in turn affects the behavior of C<< <> >>; see L for more details. By @@ -107,6 +111,7 @@ leaving a backup of the original data from each file in a new C<.c.orig> file. =head2 How can I copy a file? +X X (contributed by brian d foy) @@ -123,13 +128,14 @@ open the original file, open the destination file, then print to the destination file as you read the original. =head2 How do I make a temporary file name? +X If you don't need to know the name of the file, you can use C with C in place of the file name. The C function creates an anonymous temporary file. open my $tmp, '+>', undef or die $!; - + Otherwise, you can use the File::Temp module. use File::Temp qw/ tempfile tempdir /; @@ -175,6 +181,7 @@ temporary files in one process, use a counter: } =head2 How can I manipulate fixed-record-length files? +X X The most efficient way is using L and L. This is faster than using @@ -206,6 +213,7 @@ group or loop over them with for. It also avoids polluting the program with global variables and using symbolic references. =head2 How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles? +X X X As of perl5.6, open() autovivifies file and directory handles as references if you pass it an uninitialized scalar variable. @@ -234,6 +242,7 @@ If you want to create many anonymous handles, you should check out the Symbol or IO::Handle modules. =head2 How can I use a filehandle indirectly? +X An indirect filehandle is using something other than a symbol in a place that a filehandle is expected. Here are ways @@ -329,15 +338,25 @@ It's the syntax of the fundamental operators. Playing the object game doesn't help you at all here. =head2 How can I set up a footer format to be used with write()? +X