in reply to comparison with bitwise operators

if ($var ~~ [2, 3])

Requires 5.10.1.

Replies are listed 'Best First'.
Re^2: comparison with bitwise operators
by LanX (Saint) on Jan 14, 2011 at 02:55 UTC
    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

      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
      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.