In perl 5, values and variables are rather mushed together. The short answer is that that the object reference's referent, be it an array, hash, or scalar, is blessed into a package. This SV-like thing (as it may be an AV, HV, CV, or GV (the latter two if you're getting really weird)) has a little note tacked onto it saying that it's now an object, and marking the package the object belongs to.

When you assign to the entire array/hash/scalar that is your object, perl doesn't generate a new array/hash/scalar--it cleans it out and reuses it, including any blessing on it. (Yes, in some circumstances magic is removed. This isn't one of them)

You can check this with this little snippet:

$foo = \%bar; print $foo, "\n"; %bar = (); $foo = \%bar; print $foo, "\n";
which produces the output
HASH(0x80d0b84)
HASH(0x80d0b84)
showing that %bar hasn't moved. (And is, therefore, the same variable)

In reply to Re: Where is blessing magic located? by Elian
in thread Where is blessing magic located? by John M. Dlugosz

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.