in reply to Re^6: Scoping question - will file handle be closed? ("global")
in thread Scoping question - will file handle be closed?

A "global" cannot become "lexically inaccessible". That's what "global" means.

I think your basic misconception comes from the good old days of Perl 4 and Perl 5.005, where Perl did not have lexical filehandles. The global variables holding the data on filehandles were more or less identical to a string. But this has changed with Perl 5.6.1, which was released in 2003 I think.


Comment on Re^7: Scoping question - will file handle be closed? ("global")
Replies are listed 'Best First'.
Re^8: Scoping question - will file handle be closed? (5.6.1)
by tye (Cardinal) on Jul 29, 2015 at 14:27 UTC

    Perl 5.006_001 taught Perl itself how to do what was being done in vanilla Perl code before that. See Symbol for some remnants of that prior art.

    People were getting lexical file handles that worked just fine in Perl prior to 5.006_001 by doing things rather close to:

    my $fh = do { local *FH; \*FH };

    That is, use local to get Perl to create an extra GLOB, take a reference to that glob, then let local remove that GLOB from the symbol table so you have a GLOB that isn't global and will be destroyed based on lexical scope (and reference counting).

    Symbol actually jumps through more hoops than my one-line example above. But it used to be pretty darn close to that.

    - tye