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').
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|