"Glob" is another name for "symbol table entry". Symbol table entries have multiple fields, one for each data type (scalar, hash, array, etc).

$abc = 'xyz'; print(${*{abc}{SCALAR}}, "\n"); # xyz

When you modify a package variable, you modify the data in the appropriate field of the appropriate symbol table entry.

$glob = *def = *abc; $abc = 'xyz'; print($abc , "\n"); # xyz print($def , "\n"); # xyz print(${$glob }, "\n"); # xyz print(${*{abc }{SCALAR}}, "\n"); # xyz print(${*{def }{SCALAR}}, "\n"); # xyz print(${*{$glob}{SCALAR}}, "\n"); # xyz

Same goes when you localize a package variable. You're localizing the SCALAR field of the symbol table entry. It doesn't matter how you get to the symbol table entry (be it $_ or $alias0, for example), because the value is not associated with the symbol ($_), but with the symbol table entry (${*_{SCALAR}}).

$glob = *def = *abc; $abc = 'xyz'; print($abc , "\n"); # xyz print($def , "\n"); # xyz print(${$glob }, "\n"); # xyz print(${*{abc }{SCALAR}}, "\n"); # xyz print(${*{def }{SCALAR}}, "\n"); # xyz print(${*{$glob}{SCALAR}}, "\n"); # xyz local $def = 'uvw'; print($abc , "\n"); # uvw print($def , "\n"); # uvw print(${$glob }, "\n"); # uvw print(${*{abc }{SCALAR}}, "\n"); # uvw print(${*{def }{SCALAR}}, "\n"); # uvw print(${*{$glob}{SCALAR}}, "\n"); # uvw

In short, *abc = *def; makes the symbols abc and def the same. Only changes to the globs can undo this. local $abc doesn't affect the glob *abc (or *def), only the scalar component of it.


In reply to Re^3: Understanding typeglobs and local() by ikegami
in thread Understanding typeglobs and local() by whio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.