Hi Alexey, If I remember correctly, when you assign a value to an lvalue like this:
$foo = 1; The value of the assignment is the value on the right hand side of the equal sign. So when you do something like: if ($foo=2){...} It has the same effect as this: $foo=2; If (2){...} The condition is always true, and the compiler will wonder your attempt here. Similarly, when you write: If ($foo=$bar){...} it is translated as: $foo=$bar; If ($bar){...} The condition is completely valid, and thus compiler won't complain. Cheers, Jing On 15 Aug 2013, at 01:21, Alexey Mishustin <shum...@shumkar.ru> wrote: > Hello all, > > If I make a typo and write a single "equals" operator here: > > #!/usr/bin/perl > > use strict; > use warnings; > > my $foo = 1; > my $bar = 2; > > if ($foo = 2) { > print "yes\n"; > } > else { > print "no\n"; > } > > ...then the "warnings" pragma works OK and tells me "Found = in > conditional, should be ==..." > > But if I make the same typo and write a single "equals" operator there: > > #!/usr/bin/perl > > use strict; > use warnings; > > my $foo = 1; > my $bar = 2; > > if ($foo = $bar) { > print "yes\n"; > } > else { > print "no\n"; > } > > ... then I get no warning; the script output is "yes". > > Why is it so? > > How could I catch such typos? > > -- > Regards, > Alex > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/