Quoth (e-mail address removed):
I believe the order of operations is always well-defined in Perl: that
is, I don't know of any cases where it's been changed, nor any cases
where changing the order wouldn't be considered a bug.
TL;DR: show me where Perl systematically talks about order of
evaluation, except implicitly in some places, or talks about anything
like "sequence points".
I don't know of any place that Perl explicitly defines the order of
evaluation and refers to anything like C's "sequence points", except
where implied by things like "If the argument before the ? is true,
the argument before the : is returned, otherwise the argument after
the : is returned.". For example, for ++ and --, man perlop has
Note that just as in C, Perl doesn't define when the variable is
incremented or decremented. You just know it will be done sometime
before or after the value is returned. This also means that
modifying a variable twice in the same statement will lead to
undefined behavior. Avoid statements like:
$i = $i ++;
print ++ $i + $i ++;
Perl will not guarantee what the result of the above statements
is.
But C actually *does* define when the increment or decrement happens:
some time after the previous sequence point and before the next one.
C would not have sequence points in the problematic areas above, mind
you, so that wouldn't matter in these two lines. But C does define
that in
... (i++, i) ...
the increment happens no later than the comma operator, so the value
of "i" alone is the incremented version. (If I'm reading a draft
standard right, if it matches the current version, and if my old
neurons are firing right.)
In this case, '=>' is just sugar for ',', so the order would be
well-defined even in C.
No it would not. In the map above, the tokens "=>" and "," are not
comma operators, which in C would cause a sequence point. The only
place I know of in C where "," represents a list of values is in
initializations of arrays or structs or the like, and the draft I saw
(can't find the real standard) has "The evaluations of the
initialization list expressions are indeterminately sequenced with
respect to one another and thus the order in which any side effects
occur is unspecified."