"Perl Programmers Reference Guide (англ.) (программ.) /19.12.1998/ " - читать интересную книгу автора


14/Jun/98 perl 5.005, patch 02 19





PERLDATA(1) Perl Programmers Reference Guide PERLDATA(1)


using the _l_o_c_a_l_(_) operator. These last until their block
is exited, but may be passed back. For example:

sub newopen {
my $path = shift;
local *FH; # not my!
open (FH, $path) or return undef;
return *FH;
}
$fh = newopen('/etc/passwd');

Now that we have the *foo{THING} notation, typeglobs
aren't used as much for filehandle manipulations, although
they're still needed to pass brand new file and directory
handles into or out of functions. That's because
*HANDLE{IO} only works if HANDLE has already been used as
a handle. In other words, *FH can be used to create new
symbol table entries, but *foo{THING} cannot.

Another way to create anonymous filehandles is with the
IO::Handle module and its ilk. These modules have the
advantage of not hiding different types of the same name
during the _l_o_c_a_l_(_). See the bottom of the open() entry in
the _p_e_r_l_f_u_n_c manpage for an example.

See the _p_e_r_l_r_e_f manpage, the _p_e_r_l_s_u_b manpage, and the
section on _S_y_m_b_o_l _T_a_b_l_e_s in the _p_e_r_l_m_o_d manpage for more
discussion on typeglobs and the *foo{THING} syntax.