in reply to Re: Re: Where is blessing magic located?
in thread Where is blessing magic located?

You said it yourself -- it's the same object. Try this:

my %hash; my $x = \%hash; my $y = \%hash; print "($x) [$y]\n";

The blessing isn't associated with the value; it's attached to the container. bless adds or changes that through a reference. Since you have two references to the same thing, and since you can only have one blessing per container, you're seeing the expected and designed behavior.

If you want two different objects, you need two different containers.

(I'm using the word container to differentiate between a variable and its value.)

Replies are listed 'Best First'.
Re: Re: Re: Re: Where is blessing magic located?
by John M. Dlugosz (Monsignor) on Nov 06, 2002 at 19:00 UTC
    (I'm using the word container to differentiate between a variable and its value.)

    That's the part I was missing, not the blessing, initially.

    For the scalar, it is obvious that assignment to it doesn't change the container. For the hash, I was thinking "initialization" in C++ or reference-based things like in Java and Smalltalk, expecting assigning one hash to another to change the object's identity too.

    I see now that assignment of a list (even if that's where you are declaring it) to a hash repopulates it but doesn't change its identity. In that respect it's no different than a scalar.

    That's what I get for working on stuff late at night.

    —John