in reply to confused: string and number comparison

moritz use of eq is what you need as it's the most clear. However, regex is always an option too.

if ($cell =~ m/^[ 0]$/) { # skip it }

Replies are listed 'Best First'.
Re^2: confused: string and number comparison
by wwe (Friar) on Mar 23, 2011 at 18:23 UTC
    thanks once again to everybody.

    I asked the question as it was not clear for me why comparing 0 to a non-empty string returns true. The other fact I came along during my test for this issue was that undef == 0 also returns true.

    After our discussion and bit more thinking my understanding changed to: the string or undef doesn't represent any (other) number so the '==' operator treats this as '0'. The only other possibility would be always return false in case one or both options are not numeric. Current behavior is surprising for me but maybe it has also some advantages.

    Perhaps a perl guru spend some seconds talking about it if he comes here...