in reply to Create a new operator, get LHS

»»» This post is about alpha status Perl 6, not rock solid Perl 5 «««

In Perl 6, operators are defined by subs. Operator subs have to have an appropriate name and signature. They get automatically added to the Perl 6 grammar in the current lexical scope as soon as their name and signature have been successfully parsed.

For example, infix operators have a name of the form 'infix:<op>' and two parameters. So the code:

sub infix:<foo> ($lhs, $rhs) { dd $lhs }; sub infix:<in> ($lhs, @rhs) { dd @rhs }; 1 foo 2; 3 in [3,4];
prints (via `dd`, the built in datadumper):
$lhs = 1 @rhs = [3, 4]

For more details start at the Defining Operators section in the official end user doc.