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

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