in reply to Re^5: eval order of args to a sub
in thread eval order of args to a sub
"Operator associativity" defines what happens if a sequence of the same operators is used one after another: whether the evaluator will evaluate the left operations first or the right. For example, in "8 - 4 - 2", subtraction is left associative so Perl evaluates the expression left to right. "8 - 4" is evaluated first making the expression "4 - 2 == 2" and not "8 - 2 == 6".This answers the question "Which minus operator will be evaluated first?" But our question is different: "Will a given operator evaluate its left-hand or right-hand argument first?"
In other words, what if the code were foo() - bar() - baz()? Will foo() execute before bar(), or the reverse? Operator associativity has nothing to say about that. This is the same issue as $i++ * $i and foo($i++, $i).
I've looked through the docs, and it's not there. Perl doesn't define the evaluation order of subexpressions.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: eval order of args to a sub
by ikegami (Patriarch) on Jun 03, 2007 at 15:00 UTC | |
by shmem (Chancellor) on Jun 04, 2007 at 01:15 UTC | |
by mrpeabody (Friar) on Jun 04, 2007 at 10:41 UTC | |
by ikegami (Patriarch) on Jun 04, 2007 at 13:38 UTC | |
by shmem (Chancellor) on Jun 05, 2007 at 09:49 UTC |