Re: Ternary operator



On Fri, Sep 11, 2009 at 14:54, Chas. Owens <chas.owens@xxxxxxxxx> wrote:
snip
In case it isn't clear enough, my question (not directly to you, but
to the perl maintainers) is "Where does perl document the ternary
operator's behaviour of only evaluating either the second or the third
argument, never both?" I have looked in perldoc perlop. If you have a
better place for me to look, by all means let me know. But if it's not
in perlop, why isn't it?
snip

It is fully documented in the source code of Perl; as many things are.
 It is not documented the way you want in perlop because most people
understand the way it is currently documented there.
snip

Apparently it is also documented, to the level of detail I think you
require, in the 3rd edition of the Camel:

As in C, ?: is the only trinary operator. It's often called the
conditional operator because it works much like an if-then-else,
except that, since it's an expression and not a statement, it can be
safely embedded within other expressions and functions calls. As a
trinary operator, its two parts separate three expressions:

COND ? THEN : ELSE

If the condition COND is true, only the THEN expression is evaluated,
and the value of that expression becomes the value of the entire
expression. Otherwise, oly the ELSE expression is evaluated, and its
value becomes the value of the entire expression.

Scalar or list context propagates downward into the second or third
argument, whichever is selected. (The first argument is always in
scalar context, since it is a conditional.)

More follows, but you get the idea.

--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
.



Relevant Pages

  • Re: know-how(-not) about regular expressions
    ... "appending" to a variable. ... Perl would have to spend all its time on reallocbecause ... To isolate what I am seeing, I am posting a benchmark that simulates ...
    (comp.lang.perl.misc)
  • Re: Requesting advice how to clean up C code for validating string represents integer
    ... [Java to Lisp] ... [Perl to Lisp] ...
    (comp.lang.c)
  • Re: How to use GUI: Win32::GUI If You Need Accessibility
    ... I will press a key to convert, and it should give me the converted rtf8/unicode text in another text box <snip> ... coming from a win32 api/C/C++ background. ... the exact font metrics that can be used to write resolution, font and DPI independent code in Windows apps. ... Perl will crash consistantly with a highly cryptic error message if you try to use the two at once. ...
    (comp.lang.perl.misc)
  • Re: How to use GUI: Win32::GUI If You Need Accessibility
    ... I will press a key to convert, and it should give me the converted rtf8/unicode text in another text box <snip> ... coming from a win32 api/C/C++ background. ... the exact font metrics that can be used to write resolution, font and DPI independent code in Windows apps. ... Perl will crash consistantly with a highly cryptic error message if you try to use the two at once. ...
    (comp.lang.perl.misc)
  • Re: @array a copy of @names???
    ... It started in the 3rd edition of Learning Perl. ... That's really a foreach loop, ... least) an even worse confusion in the readers mind: ...
    (perl.beginners)