On 2012-04-03 18:55, timothy adigun wrote:
Hi Stan,
Please check my comments below:

     $test{one} eq "first" ?
     $test{one} .= " is the worst\n" :
     ( $test{two} .= " is the best\n");

This is not what the ternary (conditional operator) is for. As I said in my last post, it is used for selecting from two values, NOT for making changes because of a condition.

  You can also see perldoc perlop, under *Conditional Operator* sub-topic.

Where it states, as its opening statement:

"Ternary "?:" is the conditional operator, just as in C. It works much like an if-then-else. If the argument before the ? is true, the argument before the : is returned, otherwise the argument after the : is returned."

perlop doesn't even hint that it is used to modify existing variables. Even the examples are clear cut and dried.

Moreover, there isn't a single example in that perlop section that describes using parenthesis in the fashion your advice above shows. The Perlish way to use parens with the conditional operator was described in my last email. Here it is here again:

$x = ( $y == 1 )
  : 5
  : 10;

Here's the link to the perlop conditional op section again:

http://perldoc.perl.org/perlop.html#Conditional-Operator

Cheers,

Steve

--
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