in reply to Perl OOP

Blessing essentially means that the $self hash can now use any function in XYZ class for manipulation.
Close enough.
My question is, can we have two hashes (say $self1 and $self2) and both being blessed with the same class within the constructor?
Sure we can — this is Perl — but you'd have to be careful lest you drop one on the floor. To wit...
do $self1 and $self2 form two separate objects after being blessed?
Yes. Quite.
How then are $self1 and $self2 connected/related in any way?
Perl doesn't connect them internally in any way; they're unrelated except for being blessed into the same class. If you want them connected, you could do it yourself. For example, you could have data members in each hash which are references to the other...
$self1->{'other'} = $self2; $self2->{'other'} = $self1;
Or you could store them in some container...
push @all_your_Base, $self1, $self2;
I think the important point here is that if you have two (or more) blessed objects of a given class, they must all have internal data structures that work with the methods of the class. But if the different objects are meant to have different behaviors, then by Jah you'd better make them different classes. That's why Jah gave us the ability to make different classes. :-)

Replies are listed 'Best First'.
Re^2: Perl OOP
by hardburn (Abbot) on Oct 11, 2004 at 14:57 UTC

    you could have data members in each hash which are references to the other

    Careful with this one. You'll want to weaken the references (with Scalar::Util::weaken() or some such) so that Perl's refcounting GC doesn't trip over it.

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.