September 2017
Beginner
402 pages
9h 52m
English
The : operator does not look like an ordinary infix operator. It is used to separate the invocant argument in method calls. The method call in this call looks like a call to a regular function. Let's see this in a simple example.
First, we will call the index method on the $string.
my $string = 'Hello, World!';my $pos = $string.index('W');say $pos; # 7
The same effect can be achieved by the following lines of code:
my $pos = index($string: 'W');say $pos; # 7
As you can see, the $string variable is passed as the first argument of the index routine and is separated from the second argument with a colon.
Read now
Unlock full access