πŸ“˜ Prefix operator | in Perl 6

πŸ“˜ Prefix operator | in Raku

N. B. Perl 6 has been renamed to Raku. Click to read more.


| flattens the compound objects into a list. For example, this operator should be used when you pass a list to a subroutine, which expects a list of scalars:

sub sum($a, $b) {
Β Β Β  $a + $b
}Β 

my @data = (10, 20);
say sum(|@data); # 30

Without the | operator, the compiler will report an error, because the subroutine expects two scalars and cannot accept an array as an argument:

Calling sum(Positional) will never work with declared signature ($a, $b)

Leave a Reply

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code