Given the code:
my $x = 1;
$x = $x * 5 * ($x += 5);
I would expect $x
to be 180
:
$x = $x * 5 * ($x += 5); #$x = 1
$x = $x * 5 * 6; #$x = 6
$x = 30 * 6;
$x = 180;
180;
But instead it is 30
; however, if I change the ordering of the terms:
$x = ($x += 5) * $x * 5;
I do get 180
. The reason I am confused is that perldoc perlop
says very plainly:
A TERM has the highest precedence in Perl. They include variables, quote and quote-like operators, any expression in parentheses, and any function whose arguments are parenthesized.
Since ($x += 5)
is in parentheses, it should be a term, and therefore executed first, regardless of the ordering of the expression.