Hi Alexander,
Perl is not C.
Let's look at a common idiom in Perl:
while(my $line = <>) {
do_something($line);
}
This is an assignment in a conditional operator. It does fortunately not emit a warning. Let's look at a more or less equivalent code in C:
#include <stdio.h>
#include <stdlib.h>
int get_val(void);
int main(void) {
int i, x, y;
i = x = y = 0;
while (x = get_val()) {
i++;
printf("in loop\n");
if(i == 1) {
exit(1);
}
}
return i;
}
int get_val(void) {
return(1);
}
Compiled with LANG=C gcc -Wall -pedantic -o warning warning.c it does emit the following:
warning.c: In function 'main':
warning.c:11: warning: suggest parentheses around assignment used as t
+ruth value
IMHO, it proves: Perl is not C, C is not Perl. C is a compiled language. Perl is a interpreted language.
In my opinion, the above Perl idiom should not emit a warning like C does.
Best regards
McA
P.S.: A ++ for your comparison.
-
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.