in reply to Re: Can you guess the result? Is it a bug?
in thread Can you guess the result? Is it a bug?

Okay, but now there's a bit of a discrepancy (not a bug, I guess, but something to wonder about):

Without the parens around "$test", the first two examples produce a warning:

Found = in conditional, should be == at -e line 1.
but the third example ("= undef") does not produce any warning. (I'm running 5.8.0, in case that makes a difference.)

Replies are listed 'Best First'.
Re: Re: Re: Can you guess the result? Is it a bug?
by dga (Hermit) on Jul 31, 2003 at 22:06 UTC

    The warning is just trying to help you out so that you don't have an if that evaluates to a constant boolean value which these all do. Consider:

    ... if($val == 3); #versus ... if($val = 3);

    In the first is checks to see if $val is 3 and in the second it sets $val to be 3 and then checks $val for truth which in this case is always true. So for normal situations that line should just be:

    ...; $val=3;

    Which would have the same effect in my little sample program.