Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: variable set to 0 ? 0 : 1

by Zaxo (Archbishop)
on Sep 06, 2002 at 05:14 UTC ( [id://195578]=note: print w/replies, xml ) Need Help??


in reply to variable set to 0 ? 0 : 1

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,
Zaxo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://195578]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found