in reply to Re: is behaviour undefined for string comparision with ==
in thread is behaviour undefined for string comparision with ==

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
  • Comment on Re^2: is behaviour undefined for string comparision with ==

Replies are listed 'Best First'.
Re^3: is behaviour undefined for string comparision with ==
by GrandFather (Saint) on Feb 17, 2006 at 00:09 UTC

    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
Re^3: is behaviour undefined for string comparision with ==
by spiritway (Vicar) on Feb 17, 2006 at 00:15 UTC

    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.