Conditional Operator: (condition) ? statement_if_true : statement_if_false; : Conditional Operators « Language Basics « Perl






Conditional Operator: (condition) ? statement_if_true : statement_if_false;

   

$coin = int (rand(2 )) + 1; # Generate a random number between 1 and 2
print ( $coin == 1 ? "You tossed HEAD\n" : "You tossed TAIL\n" );

   
    
    
  

Related examples in the same category

1.Conditional Operators and print statement
2.? operator