X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperldata.pod;h=407a25204f3b83a49a5648b1875697dcba437566;hb=1fd81fbbe87d964ad1f7dbdce41e36f3781dcf82;hp=7842039e896430757b4dd835fd50089ac435932e;hpb=0135f10892ed8a21c4dbd1fca21fbcc365df99dd;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perldata.pod b/pod/perldata.pod index 7842039..407a252 100644 --- a/pod/perldata.pod +++ b/pod/perldata.pod @@ -72,7 +72,7 @@ however, which don't have an initial special character. You can't have a filehandle named "log", for instance. Hint: you could say C rather than C. Using uppercase filehandles also improves readability and protects you from conflict -with future reserved words.) Case I significant--"FOO", "Foo" and +with future reserved words.) Case I significant--"FOO", "Foo", and "foo" are all different names. Names that start with a letter or underscore may also contain digits and underscores. @@ -135,7 +135,7 @@ Scalar variables may contain various kinds of singular data, such as numbers, strings, and references. In general, conversion from one form to another is transparent. (A scalar may not contain multiple values, but may contain a reference to an array or hash containing multiple values.) -Because of the automatic conversion of scalars, operations and functions +Because of the automatic conversion of scalars, operations, and functions that return scalars don't need to care (and, in fact, can't care) whether the context is looking for a string or a number. @@ -513,7 +513,7 @@ Note that just because a hash is initialized in that order doesn't mean that it comes out in that order. See L for examples of how to arrange for an output ordering. -=head2 Typeglobs +=head2 Typeglobs and Filehandles Perl uses an internal type called a I to hold an entire symbol table entry. The type prefix of a typeglob is a C<*>, because @@ -522,7 +522,29 @@ pass arrays and hashes by reference into a function, but now that we have real references, this is seldom needed. It also used to be the preferred way to pass filehandles into a function, but now that we have the *foo{THING} notation it isn't often needed for that, -either. +either. It is still needed to pass new filehandles into functions +(*HANDLE{IO} only works if HANDLE has already been used). + +If you need to use a typeglob to save away a filehandle, do it this way: + + $fh = *STDOUT; + +or perhaps as a real reference, like this: + + $fh = \*STDOUT; + +This is also a way to create a local filehandle. For example: + + sub newopen { + my $path = shift; + local *FH; # not my! + open (FH, $path) || return undef; + return \*FH; + } + $fh = newopen('/etc/passwd'); + +Another way to create local filehandles is with IO::Handle and its ilk, +see the bottom of L. See L, L, and L for more discussion on typeglobs.