On Aug 14, 2013, at 11:34 AM, Alexey Mishustin wrote:
> Hi Jing,
>
> Thanks for the reply.
>
> So, there is no built-in way to catch these typos?
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.
However, the construct
if( $foo = 2 ) {
...
would mean: "assign value of 2 to variable $foo and test if the result is
logically true", which doesn't make sense because 2 is always logically true
and there is no point in testing it.
That is why the Perl compiler can give you a warning in the second case but not
in the first.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/