From 36392fcf0bb917360f3e083a8d5bb2f65f72c346 Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Mon, 20 Mar 2000 20:53:25 +0000 Subject: mention handle autovivification in perldata (from Johan Vromans) p4raw-id: //depot/perl@5838 --- pod/perldata.pod | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'pod') 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 and C 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("; + # $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 -- cgit v1.2.1