2009/9/11 Uri Guttman <u...@stemsystems.com>:
>>>>>> "SB" == Steve Bertrand <st...@ibctech.ca> writes:
>
>  SB> Besides consistently forgetting how to properly spell "ternary", I
>  SB> can't, for some reason, embed it's use into my brain no matter how
>  SB> much I read.
>
> ternary op is an official name but it has many nicknames so they are
> worth knowing too. conditional expression is longer but very
> descriptive. hook/colon is a slang name.
>
> it is actually very simple to understand. the key point to knowing it
> and how to use it is that the 2 value expressions SHOULD NOT have side
> effects. that means changing something by assignment or other
> modification. your example below is one exception to that.

Does ?: guarantee that only one arm of its conditions will be executed? eg:

# @_ has 3 elements

$x = $flag ? shift : push;

# is it now guaranteed that @_ has 2 elements?

In the above example, is it guaranteed that *either* shift *or* push
happens, but *not* both? perl won't calculate both sides in advance
and assign only one to $x?

I ask because this is the behaviour I expect from C and C++, it's very
important (Steve's original  ? shift : {} is broken without it), but
it's not explicitly stated in perldoc perlop. perlop *does* explain
the short-circuit behaviour of qw(|| && // or and) and their use for
control flow, but is silent on ?:'s control flow behaviour. Is this
documented in perldoc, and if so where? Why is it not documented in
perldoc perlop? (Perhaps perldoc isn't quite as great as my post in a
parallel thread states...)

Phil

-- 
"I have always wished for my computer to be as easy to use as my
telephone; my wish has come true because I can no longer figure out
how to use my telephone."
  --Bjarne Stroustrup

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to