in reply to is behaviour undefined for string comparision with ==

the behaviour is well defined, left and right arguments to == are converted to numbers, yielding 0 in that case, and then compared. On my computer I get the expected
equal equal

If you get something different, you are doing something wrong or you have found a bug. Which version of perl and OS are you using?

Replies are listed 'Best First'.
Re^2: is behaviour undefined for string comparision with ==
by bart (Canon) on Feb 16, 2006 at 23:30 UTC
    I enable warnings and thus I get:
    Argument "mssql" isn't numeric in numeric eq (==) at test.pl line 3. Argument "mssql" isn't numeric in numeric eq (==) at test.pl line 3. equal Argument "mssql" isn't numeric in numeric eq (==) at test.pl line 5. Argument "MSSQL" isn't numeric in numeric eq (==) at test.pl line 5. equal

    Enough clues, already?

Re^2: is behaviour undefined for string comparision with ==
by edwardt_tril (Sexton) on Feb 16, 2006 at 23:55 UTC
    actually the second comparions should be an eq. I mistyped.
    I just not believe the behaviour is not well defined as my
    coworker says. Because string will act like integer for Hex based like 'A', and we can do + - * / on it. I do not see
    why Perl is unable to do that for ==. Any Perl language specification reference to this? I want to convince her.
    Thanks

      See Equality Operators in perlop and perlnumber may help

      Point your coworker to this thread - she may become so enamoured of PerlMonks that she joins. :)


      DWIM is Perl's answer to Gödel

      It's very well defined. If you string contains numerals, then the numerals will be converted to numbers. Strings without numerals will be converted to zero. The following code will consider the two strings as equal:

      my $str1 = "perl123"; my $str2 = "aaaa123"; if ($str1 == $str2) { print "Strings are equal\n"; }

      You can check out perldoc perlop to find more information on this.