📘 Universal comparison operators before and after in Perl 6

📘 Universal comparison operators before and after in Raku

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


before and after are the comparison operators, which work with operands of different types. It returns a Boolean value of either True or False depending on which operand was considered to be ordered earlier or later.

Type coercion is similar to how it happens with the cmp operator.  Remember that depending on the data types the comparison of similar-looking strings or numbers may give different results because the strings are compared alphabetically, while the numbers are ordered by their values:

say 10 before 2;      # False
say '10' before '2';  # True 
say 10 before 20;     # True
say '10' before '20'; # True

Leave a Reply