in reply to If condition logic yielding partially correct output

Take a look at What is true and false in Perl. The string 'test' (being not equal to an empty string) passes your first clause; and since the string 'test' is not equal to the string '0', in numeric context, it passes the second clause. Since 1 && 1 evaluate to 1, 'test' satisfies your if condition.

Update -- clarified that we are talking about strings in the second clause

----
I Go Back to Sleep, Now.

OGB

  • Comment on Re: If condition logic yielding partially correct output

Replies are listed 'Best First'.
Re^2: If condition logic yielding partially correct output
by dsheroh (Monsignor) on Aug 13, 2009 at 11:27 UTC
    Erm... "test" is equal to 0 in numeric context, so if (($key ne "") && ($key != 0)) evaluates as false for "test" ("test" ne "" is true, "test" != 0 is false; true && false = false), which is why the print after the if doesn't execute.
Re^2: If condition logic yielding partially correct output
by Anonymous Monk on Aug 13, 2009 at 11:12 UTC