in reply to Evaluating the condition ($x)
So, short answer: use more brackets. I sprinkle a fair number of brackets in my code, and I'm also generous with white space. It helps clarify the meaning of the code, and hopefully avoids situations like this.
Longer answer: For your first example, I would write that as
rather than use a bare ternary as you have done. A ternary is more useful if you're in the middle of a print statement, like this:if ( $x ) { print "true\n"; } else { print "false\n"; }
The ternary operator comes from C -- it's a great piece of shorthand.print "The truth value of x is " . ( $x ? 'true' : 'false' ) . "\n";
|
|---|