in reply to Re^2: Confused by Perl ternary operator
in thread Confused by Perl ternary operator
After writing the above, I checked perlop.pod, and technically you are correct. ?: isn't documented as short-circuiting, so perl potentially could evaluate the 2nd and 3rd operands before testing the first one. However, I believe that it is intended to short-circuit and will submit a patch to the doc.
As an interesting side note, structures with else or elsif are implemented using condexpr (the ?: operator). That is,
is identical toif (foo) { bar } else { baz }
so the short-circuiting of ?: is pretty guaranteed.foo ? do { bar } : do { baz }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Confused by Perl ternary operator
by diotalevi (Canon) on Aug 24, 2004 at 00:13 UTC |