πŸ“˜ Universal comparison operator eqv in Perl 6

πŸ“˜ Universal comparison operator eqv in Raku

N. B. Perl 6 has been renamed to Raku. Click to read more.


eqv is an operator that tests the two operands for equivalence. It returns the True value if the operands are of the same type and contain the same values.

my $x = 3;
my $y = 3;
say $x eqv $y; # True

An example with a bit more complex data structures:

my @a = (3, 4);
my @b = (3, 4, 5);
@b.pop;
say @a eqv @b; # True

Note that because the integer and the floating-point types are different data types, comparing two equal numbers may give a False result. The same applies to the comparison with a string containing a numeric value.

say 42 eqv 42.0; # False
say 42 eqv "42"; # False

It is even trickier when one of the operands is of the Rat value.

say 42 eqv 84/2;Β Β Β Β Β Β  # False, 84/2 is Rat
say 42 eqv (84/2).Int; # True, the value is cast to Int

Leave a Reply

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code