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.
In reply to Re^3: No warning when assiging to a variable
by McA
in thread No warning when assiging to a variable
by mikeraz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |