Change 15416 by jhi@alpha on 2002/03/22 15:03:05
Undo #15415, allow the faq people to catch up first.
Affected files ...
..... //depot/perl/pod/perlfaq4.pod#69 edit
..... //depot/perl/pod/perlfaq5.pod#43 edit
..... //depot/perl/pod/perlfaq6.pod#36 edit
Differences ...
==== //depot/perl/pod/perlfaq4.pod#69 (text) ====
==== //depot/perl/pod/perlfaq5.pod#43 (text) ====
Index: perl/pod/perlfaq5.pod
--- perl/pod/perlfaq5.pod.~1~ Fri Mar 22 08:15:05 2002
+++ perl/pod/perlfaq5.pod Fri Mar 22 08:15:05 2002
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq5 - Files and Formats ($Revision: 1.13 $, $Date: 2002/03/16 15:37:26 $)
+perlfaq5 - Files and Formats ($Revision: 1.12 $, $Date: 2002/03/11 22:25:25 $)
=head1 DESCRIPTION
@@ -496,7 +496,6 @@
open FILE, "<", " file "; # filename is " file "
open FILE, ">", ">file"; # filename is ">file"
-
It may be a lot clearer to use sysopen(), though:
@@ -764,7 +763,21 @@
which allow you to tie an array to a file so that accessing an element
the array actually accesses the corresponding line in the file.
-You can read the entire filehandle contents into a scalar.
+On very rare occasion, you may have an algorithm that demands that
+the entire file be in memory at once as one scalar. The simplest solution
+to that is
+
+ $var = `cat $file`;
+
+Being in scalar context, you get the whole thing. In list context,
+you'd get a list of all the lines:
+
+ @lines = `cat $file`;
+
+This tiny but expedient solution is neat, clean, and portable to
+all systems on which decent tools have been installed. For those
+who prefer not to use the toolbox, you can of course read the file
+manually, although this makes for more complicated code.
{
local(*INPUT, $/);
@@ -777,13 +790,6 @@
$var = do { local $/; <INPUT> };
-For ordinary files you can also use the read function.
-
- read( INPUT, $var, -s INPUT );
-
-The third argument tests the byte size of the data on the INPUT filehandle
-and reads that many bytes into the buffer $var.
-
=head2 How can I read in a file by paragraphs?
Use the C<$/> variable (see L<perlvar> for details). You can either
==== //depot/perl/pod/perlfaq6.pod#36 (text) ====
Index: perl/pod/perlfaq6.pod
--- perl/pod/perlfaq6.pod.~1~ Fri Mar 22 08:15:05 2002
+++ perl/pod/perlfaq6.pod Fri Mar 22 08:15:05 2002
@@ -9,7 +9,7 @@
decoding a URL and checking whether something is a number are handled
with regular expressions, but those answers are found elsewhere in
this document (in L<perlfaq9>: ``How do I decode or create those %-encodings
-on the web'' and L<perfaq4>: ``How do I determine whether a scalar is
+on the web'' and L<perlfaq4>: ``How do I determine whether a scalar is
a number/whole/integer/float'', to be precise).
=head2 How can I hope to use regular expressions without creating illegible and
unmaintainable code?
End of Patch.