๐Ÿ“˜ 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

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