in reply to objects are references, right?
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 :-)
|
|---|