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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.