in reply to Re: comparison with bitwise operators
in thread comparison with bitwise operators

Careful, there are subtle differences!

Which comparison operator ~~ internally choses, depends on the type of the variable:

DB<1> $a="2.0" DB<2> p [2,3] ~~ $a DB<3> p $a == 2 1 DB<4> p [2,3] ~~ $a 1

BTW: line 4 demonstrates one of the weirdest side effects of perl's auto-casting ...

Cheers Rolf

Replies are listed 'Best First'.
Re^3: comparison with bitwise operators
by ikegami (Patriarch) on Jan 14, 2011 at 05:19 UTC

    That's not the code I posted. The code I posted does not suffer from the problem you describe.

    >perl -E"$a='2.0'; say $a~~[2,3];" 1 >perl -E"$a=2; say $a~~[2,3];" 1
Re^3: comparison with bitwise operators
by LanX (Saint) on Jan 14, 2011 at 11:21 UTC
    this is a misplaced reply to 882287

    > That's not the code I posted. The code I posted does not suffer from the problem you describe.

    hmm I checked your code...

    :~$ perl -E '$a="2.0"; say [2,3] ~~ $a;' :~$ perl -E '$a="2.0"; say $a~~[2,3];'

    But not the version...I'm using 5.10.0 and not 5.10.1!

    And the line It is always commutative, i.e. "$a ~~ $b" behaves the same as "$b ~~ $a".

    has been erased from newer docs (see Smart matching in detail)...

    Anyway smartmatch is still too magic for my taste!

    Cheers Rolf

      Anyway smartmatch is still too magic for my taste!

      Smart match is too magical when using something variable on the RHS.

      I'm using 5.10.0 and not 5.10.1!

      Don't use smart-matching in 5.10.0.