📘 String comparison operator leg in Perl 6

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s