Three Operand Conditional Operator 
Author Message
 Three Operand Conditional Operator

I would like to do something like the following but get a syntax error.

print ((1?OUT1:OUT2) "The expression was true\n");

where OUT1 and OUT2 are two different filehandles and the '1' would normally be  
replaced by an expression (probably something like (count % 2))

So what is wrong with this? Where am I going astray? Is there a better (read:  
working) way of doing this?

Respond by email and I will summarize.

Bryce Jasmer



Sat, 25 Dec 1993 08:08:35 GMT  
 Three Operand Conditional Operator

Quote:

>I would like to do something like the following but get a syntax error.
>print ((1?OUT1:OUT2) "The expression was true\n");

And thanks to Raymond Chen and Randal L. Schwartz I now know that I need to do  
something like this:

$outfile = $count % 2 ? OUT1 : OUT2;
print $outfile "random output text.\n";

This is due to the fact that print and printf expect to see a filehandle and  
not an expression that ultimately results in a filehandle. Makes enough sense  
to me.

Thanks guys.

Just another C hacker converting to Perl,



Sun, 26 Dec 1993 01:15:05 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Range operators: two dots v.s. three dots

2. A question on the Conditional Operator

3. Conditional Operator behavior?

4. Ternary Conditional Operator Question

5. push onto trinary conditional operator?

6. newbie questions re conditional operators

7. Q: conditional operator and variable assignment

8. ternary conditional operator

9. conditional operator "?:"

10. problem parsing conditional operator.

11. print operand file name

12. Null right hand comma operand in hash assignment

 

 
Powered by phpBB® Forum Software