summaryrefslogtreecommitdiff
path: root/pod
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2000-03-20 20:53:25 +0000
committerGurusamy Sarathy <gsar@cpan.org>2000-03-20 20:53:25 +0000
commit36392fcf0bb917360f3e083a8d5bb2f65f72c346 (patch)
treec5a13da16a03a36de854cbdb66b4f866847ec1c2 /pod
parentf08d6ad944c4ecbe4ec19c801b6b512b040abbf6 (diff)
downloadperl-36392fcf0bb917360f3e083a8d5bb2f65f72c346.tar.gz
mention handle autovivification in perldata (from Johan Vromans)
p4raw-id: //depot/perl@5838
Diffstat (limited to 'pod')
-rw-r--r--pod/perldata.pod22
1 files changed, 22 insertions, 0 deletions
diff --git a/pod/perldata.pod b/pod/perldata.pod
index 3e10e6f3d4..ac444fa17c 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