Jeff Westman wrote:

> > At last! Thanks Bob, this /is/ how to use the conditional operator,
> > while
> >
> >     $VAL ? ( $VAL = "$VAL:$expr" ) : ( $VAL = $expr )
> >
> > /isn't/. ?: is an /operator/. It happens to have three operands
> > instead of the usual two or 1, but it is meant for deriving a
> > new value from three others, like a function.
> >
> >     sub conditional {
> >         my ($test, $val1, $val2);
> >         return $val1 if $test;
> >         return $val2;
> >     }
> >
> >     $VAL = conditional ($VAL, "$VAL:$expr", $expr)
> >
> > Rob
>
> If you ask /me/ the above code is a lot harder to read to the simple one-line
> ternary as was mentioned before (expr:true?false).

Hi Jeff,

I certainly agree, and I'm sure Rob would too.  I don't hink his point was to
recommend the conditional() function for actual use, but to outline in function
form the logic implemented by the operator.

> The ternary operation is used to make your code more concise and readable,
> but in a limited context.  IE, you can nest ternary operations ... have fun
> maintaining it!
>
> -JW

Absolutely.  Terse operations can certainly add immediacy and punch to code when
the context is small enough to be crystal clear.  Trying to pack complicated
logic into them simply imposes an equal or greater burden of unpacking the logic
whe reviewing the code.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to