Thanks to all, 2013/8/14 Jim Gibson <jimsgib...@gmail.com>:
> The problem is that the construct > > if( $foo = $bar ) { > ... > > is not always a typo. It means: "assign value of $bar to variable $foo and > test if the result is logically true", which is perfectly valid. If that were > not allowed, then you would have to write: > > $foo = $bar; > if( $foo ) { > ... > > which not everyone would like. 2013/8/14 Rob Dixon <rob.di...@gmx.com>: > The `warnings` pragma catches the first form because the value of the > conditional is a *constant* 2, so the body of the `if` will *always* be > executed and it is a fair guess that the problem is `=` instaed of `==`. > > In the second case the execution depends on the value of `$bar`, and it > is a reasonable thing to write if, say, you wanted to test a value and > assign it to a temporary variable at the same time. Perl cannot know > that the code was unintentional and will not warn you. Testing a value and assigning it - I have never done this at the same time... > I have checked both Perl::Critic and B::Lint, and neither of these check > for an assignment operator in a conditional expression. The only thing > way I can think of doing this is to write a plugin for B::Lint, which > accepts Module::Pluggable plugins. It may be possible to write something > that will do what you want. Thanks for the suggestion. I'll give a look at B::Lint. 2013/8/14 Jing Yu <logus...@googlemail.com>: > Or maybe he can write a perl script to check the "if/while" conditionals of > his perl script... > > while(<>){ > say '= is detected where == is expected at line ',"$." if > /if\s*\(\S+?=[^=]/; > } Yes, if I meet difficulties with B::Lint, I'll have nothing to do but to parse my code... Today I passed more than an hour debugging this kind of "not always a typo" in a project of few thousands lines. xD. So, I would not like this to be repeated. -- Best regards, Alex -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/