Perl 6 Programming/Operator Overloading

From Wikibooks, open books for an open world
< Perl 6 Programming
Jump to: navigation, search

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.