in reply to Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
Edit: ikegami is right, I mistook precedence for evaluation order, and just kept being blinded by that mistake. Please read his correct explanation.
If you look at the precedence list in perlop, += is of higher precedence than ,, so it will be run first, just like the multiplication will be run before the addition in $c+$c*$_
In $c+0, $c+=1; + is the highest precedence operation, so addition is indeed run first. In $tmp = $c, $c+=1; = and += are of equivalent precedences, and so are run from left to right (and that's because of the , in between).
Edit: added a ; here and a ; there, because their absence made my post look confusing.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
by smls (Friar) on Mar 04, 2014 at 23:07 UTC | |
by Eily (Monsignor) on Mar 04, 2014 at 23:29 UTC | |
by smls (Friar) on Mar 05, 2014 at 00:34 UTC | |
|
Re^2: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
by hazylife (Monk) on Mar 04, 2014 at 21:47 UTC | |
|
Re^2: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
by ikegami (Patriarch) on Mar 06, 2014 at 15:36 UTC | |
by Eily (Monsignor) on Mar 06, 2014 at 17:21 UTC |