From: Gurusamy Sarathy <gsar@cpan.org>
Date: Mon, 20 Mar 2000 20:53:25 +0000 (+0000)
Subject: mention handle autovivification in perldata (from Johan Vromans)
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=36392fcf0bb917360f3e083a8d5bb2f65f72c346;p=p5sagit%2Fp5-mst-13.2.git

mention handle autovivification in perldata (from Johan Vromans)

p4raw-id: //depot/perl@5838
---

diff --git a/lib/User/pwent.pm b/lib/User/pwent.pm
index f41aa2a..8c05926 100644
--- a/lib/User/pwent.pm
+++ b/lib/User/pwent.pm
@@ -250,7 +250,7 @@ You may ask whether one of these was implemented on the system Perl
 was built on by asking the importable C<pw_has> function about them.
 This function returns true if all parameters are supported fields
 on the build platform, false if one or more were not, and raises
-and exception if you asked about a field that Perl never knows how
+an exception if you asked about a field that Perl never knows how
 to provide.  Parameters may be in a space-separated string, or as
 separate arguments.  If you pass no parameters, the function returns
 the list of C<struct pwd> fields supported by your build platform's
diff --git a/pod/perldata.pod b/pod/perldata.pod
index 3e10e6f..ac444fa 100644
--- a/pod/perldata.pod
+++ b/pod/perldata.pod
@@ -750,6 +750,28 @@ C<*HANDLE{IO}> only works if HANDLE has already been used as a handle.
 In other words, C<*FH> must be used to create new symbol table entries;
 C<*foo{THING}> cannot.  When in doubt, use C<*FH>.
 
+All functions that are capable of creating filehandles (open(),
+opendir(), pipe(), socketpair(), sysopen(), socket(), and accept())
+automatically create an anonymous filehandle if the handle passed to
+them is an uninitialized scalar variable. This allows the constructs
+such as C<open(my $fh, ...)> and C<open(local $fh,...)> to be used to
+create filehandles that will conveniently be closed automatically when
+the scope ends, provided there are no other references to them. This
+largely eliminates the need for typeglobs when opening filehandles
+that must be passed around, as in the following example:
+
+    sub myopen {
+        open my $fh, "@_"
+	     or die "Can't open '@_': $!";
+	return $fh;
+    }
+
+    {
+        my $f = myopen("</etc/motd");
+	print <$f>;
+	# $f implicitly closed here
+    }
+
 Another way to create anonymous filehandles is with the Symbol
 module or with the IO::Handle module and its ilk.  These modules
 have the advantage of not hiding different types of the same name