Does the hash value $child->{parent} now hold the blessed hash that was created when I did $parent = new Node;, or a reference to it?
It holds a reference to the blessed hash. I think the confusion comes in part from the fact that bless needs a reference argument, but the thing that is actually blessed is the data the reference points at.

In fact, an object in perl is *not* a reference but a blessed variable (a scalar, hash, filehandle, etc.), but the only way you can usefully do anything with that object is through a reference to that variable - you can't call an instance method without a reference, and copying the data structure directly will not copy its "blessedness", but copying a reference to it will create a new reference to the same object:

# create object of My::Class my $object = bless { some => 'thing' }, "My::Class"; # create a second reference to /the same/ object my $copy = $object; # copy object data - this /will not/ create a new object # but $copy2 will be a reference to an unblessed hash # containing all the data in $object my $copy2 = { %$object }; # if you really need to "clone" an object, you need # to bless the copy too, (and mind nested objects! - # I ignored those here) my $clone = bless { %$object }, "My::Package"

Hope this helps :-)


In reply to Re: objects are references, right? by Joost
in thread objects are references, right? by rvosa

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.