in reply to Re^2: Calling a subroutine via multiple dereferences.
in thread Calling a subroutine via multiple dereferences.
scalar() may not be unique, and may change over the lifetime of the object. For instance, in this case, I've got the scalar conversion overloaded to return the class name and some basic info on the state of the class. Useful for debugging and error returns. However it is quite easy to set up two different objects so that they appear the same. Also, calling one of a few different methods will change what would be returned. (Which leads to a self-referential loop: To get the scalar value, you have to know the scalar value...)
refaddr() by contrast is stable: The object will always be in a particular location, until it is no longer that object. And no two objects may have the same location at the same time. So it is much safer to use. I don't actually care what the key is, as long as it is unique and stable, and refaddr provides that.
As for complex... Past the inside-out object, it's just an array of arrays, and the second level array is just to keep things associated. I actually looked at setting up two different arrays, but this is much simpler to keep track of.
|
|---|