|Don't ask to ask, just ask|
Re: Question about ternary conditionby anonymized user 468275 (Curate)
|on Jun 28, 2005 at 09:42 UTC||Need Help??|
The first example uses assignment before the ? operator so that the parts of the RHS of the assignment will be executed predictably according to the condition to the left of the '?'.
The second example does not do any assigning before the ?. It's true that perl will execute an 'or' or 'and' in such a non-assignment context, but (IMHO) that feature cannot be assumed for all operators and apparently not '?'.
Hope this helps.
Update: Precedence (offered later) is a tempting explanation but I think it is merely executing both assignments in the order left to right because without an assignment to drive the ?, the parser is forced to execute the lot and then go nowhere with the ? because it has no documented reason to
- but I do agree with using brackets to control the precedence or in this case, wake it up!
One world, one people