in reply to reference as hash keys and values
As already pointed out, references cannot effectively be used as hash keys.
I eventually came up with a use case once, where I really wanted to be able to identify my objects uniquely, for building Sets of unique objects and such. With a tip from a friend, I came up with the following scheme. Instead of using the reference itself, use a reliable string representation of the reference. Scalar::Util::refaddr() can provide such, for a single-process oriented use-case anyway.
my $uniqueID = Scalar::Util::refaddr( $self ); $objectsHash->{$uniqueID} = $self;
From then on, given any structure using those IDs as hash keys, you can retrieve the referenced structure/object from the $objectsHash index. Inside-out Objects use essentially the same means for a slightly different purpose. Track a unique objectID, not the object itself.
In my ideal world, concrete objects provide the override to identify themselves, but my abstract classes still want to be able to do something in the absence of that override.
--Dave
|
|---|