Open main menu

Wikibooks β

Perl 6 Programming/Operator Overloading

< Perl 6 Programming

There are only 5 types of operators: infix , prefix , postfix , circumfix and postcircumfix .

You can declare a new operator like this:

sub postfix:<!>(Int $n!) { [*] 1..$n }
say 5!; # prints 120

The above, as you can see, declares an operator '!' for calculating factorial of a Integer.