📘 String comparison operator leg in Perl 6

📘 String comparison operator leg in Raku

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


leg tells if is the two strings are equal or the left operand is less or greater than the second one. Its behaviour is similar to what <=> does for numbers or what the cmp built-in operator does in Perl 5. Like the cmp in Perl 6, the leg operator returns a value of the Order type.

say "a" leg "b";        # Less
say "abc" leg "b";      # Less
say "bc" leg "b";       # More
say "abc" leg "ABC".lc; # Same

Before the operation, the operands are converted to strings if necessary.

say 42 leg "+42"; # More
say 42 leg "42";  # Same

Leave a Reply