in reply to typeglobs and filehandles

What local really does is create a new thing and has it temporarily accessible under a global name. (OK, doesn't have to be global, you can hide hash values with local as well.) As always with Perl, that thing goes away when the last reference to it goes away. Frequently this happens when it is no longer accessible under the name of the global.

So in the snippet a new typeglob is produced, made temporarily accessible under a new name, is unaliased and returned. It is no longer accessible under that name (though it remembers the name it was created as) but continues to exist because you can still get at it.

Cute, huh? :-)

One gotcha though. Suppose you have a hash of filehandles. Well you cannot do:

while (<$fh_of{$whatever}>) { # ... }
and have it work as expected since the semantics of Perl's parsing are ambiguous. You really need to (sorry) copy the filehandle into a variable and use that variable as the filehandle.