Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Situation where warning "Found = in conditional, should be" seems obsolete

by rsFalse (Chaplain)
on Feb 09, 2021 at 00:33 UTC ( [id://11128118]=note: print w/replies, xml ) Need Help??


in reply to Situation where warning "Found = in conditional, should be" seems obsolete

For complete picture I want to share findings that this warning does appear if (1) right side of an assignment '=' operator contains a "constant" (i.e. number, string), except 'undef'; And the warning does not appear if (2) the left side of an assignment operator '=' is enclosed with parentheses or if it is an array. I think it is desired behavior. Of course if some coder have wanted to compare his array with a number (e.g. @_ == 5, i.e. if a number of elements of an array equals to 5) and he accidentally put one '=' instead of '==', warning won't appear; And example:
perl -wle '@_ = -1 .. 3; for( @_ ){ print $_; ( ) = 0 or last }'
OUTPUT:
-1 0 1 2 3
No warning.
Note that 'last' never executed because of: an assignment operator works as "list assignment operator" (because of parentheses on the left side of the '='), and an operator 'or' asked for scalar context. In scalar context list assignment operator returns a number of elements of the right side (i.e. one element: '0').

Log In?
Username:
Password:

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

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

    No recent polls found