I'm not exactly sure what you are trying to prove here, but in the first instance where you are creating the hash to assign to %x, I believe that you cannot do that assignment because until that code has finished executing everything after "%x =" is at the time an anonymous hash. After perl constructs the anonymous hash then the reference gets assigned to %x. To illustrate this...
CODE:
use Data::Dumper;
%x =
( 3 => 4,
1 => 5
);
print Dumper(\%x), $/;
%x =
( 1 => 2,
3 => $x{1}
);
print Dumper(\%x), $/;
OUTPUT:
$VAR1 = {
1 => 5,
3 => 4
};
$VAR1 = {
1 => 2,
3 => 5
};
The reason that $x{3} is assigned the 5 is because the new hash we are building for %x hasn't been finished yet and since it is an anonymous hash it still cannot be addressed. Therefore it goes and uses the previously defined %x to set $x{3}.
Something I don't know about though is if there is a notation for within an anonymous hash to have it be able to reference itself. That way you *could* use this behavior to set other values based on itself while it is building. I also remember reading a while back that hashes are constructed backwards (somebody would have to verify this because I'm not 100% sure) so it is possible that even if you could do this it would probably be a little confusing.
I'm not sure what you are getting at about the %y values being immediately bound after each statement is run because if this behavior didn't exist it would be impossible to code in perl because everything would be contingent on side effects which is a rather scary thought. After each semi-colon perl really ought to have moved all the bits around in the way I told it to.
Cool find though... I certainly never would have bothered to try and access a hash's data while constructing the hash itself. On the other hand it probably isn't the best coding practice either, but what the hell! |