πŸ“˜ Non-value argument passing in Perl 6 subs

πŸ“˜ Non-value argument passing in Raku subs

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


By default, you pass the arguments by their values. Despite that, it is not possible to modify them inside the sub. To pass a variable by reference, add the is rw trait. (Note that formally this is not a reference but a mutable argument.)

sub inc($x is rw) {
Β Β Β  $x++;
}

my $value = 42;
inc($value);
say $value; # 43

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