Uri Guttman wrote: > when will people learn?? the ternary operator is for > CHOOSING A > VALUE. it is NOT for side effects. its precedence is > designed to allow > it to be assigned, NOT to have assignments done inside. > > > NEVER USE ?: for side effects. ALWAYS use it to return a > value chosen > from two. do not break this rule and it will always work. > > $bar = ($foo == 1) ? 0 : 1 ; > > uri
I looked through perlop and was unable to find where it stated that the ternary operator should only be used in an assignment such as you've shown. Can you point out where that's located. I often use the ternary operator when working with dispatch tables. Based on your comment, I suspect that you feel that the following example is a poor use of the ternary operator. Please correct me if I'm wrong. exists $dispatch{$status} ? $dispatch{$status}->() : $dispatch{'error'}->(); -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/