The stupid question is the question not asked | |
PerlMonks |
Re: variable set to 0 ? 0 : 1by Zaxo (Archbishop) |
on Sep 06, 2002 at 05:14 UTC ( [id://195578]=note: print w/replies, xml ) | Need Help?? |
That is the trinary operator ?:. It parses like this: return (($status == 0) ? 0 : 1);. The first of the terms is evaluated in bool context. If true, the whole trinary takes the value of the expression after the question mark. If false, it takes the value after the colon. If $status is an instance of a class with overloaded operators, it may not return a simple value. Or else it may be a floating point value, with the accompanying accuracy problems in comparisons. This expression forces $status into numeric context and converts any non-zero $status to 1. The returned value is a perl numeric type, whatever $status may be. Update: By the way, your title suggests you misread the == operator as assignment. It's numeric comparison for equality, instead. Minor clarification in text. After Compline,
In Section
Seekers of Perl Wisdom
|
|