Raku Books / Perl 6 at a Glance / Code Organization / Subroutines, or subs

Non-value argument passing

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

Course navigation

Subroutines, or subs   |   Typed arguments