|Think about Loose Coupling|
How about this for $i=$i++by jynx (Priest)
|on Apr 30, 2002 at 01:54 UTC||Need Help??|
This is probably completely wrong, but...
What i think is happening is this: the reference to the variable $i is being modified by the auto-(in|de)crement operators before the addition operation because of the precedence table. The reference then gets updated for the left $i for a right-side auto-increment because we're dealing with a reference to the actual variable, not a hard-coded number -- and in the case of the post-increment, because of a bug.
This should leave $a at the value 1, but it should evaluate to 1. It evaluates to 2! Because the pre-increment updates the reference to $a on the left side of the addition operator as well. This is fine if it gets documented, but the following is a straight bug:
We get a return value of 0, and $a is set to 1 as it should be. However if $a is on the left side:
We get a return value of 1! $a is still set to 1 as it should be. If instead of $a we use some other (zeroed) variable it evaluates to 0 correctly. Somewhere Perl is messing up what happens on a right-side post-increment if the same variable is being added to itself. Maybe it's adding 1 to the left side even if it's a post-increment?
So, to explain the strange ++$a + $a++ i think it works like this:
i could be wrong :/
Here's what i ran with the results i obtained:
That's a bug imho (though i could be wrong; better explenations anyone?)
hope this helps,
update: Hmmm, even stranger.
If we take
So the first addition is probably becoming zero before the second addition is messing it up? And to further confuse things:
i think at this point i've gone too far...