πŸ“˜ Nested subs in Perl 6

πŸ“˜ Nested subs in Raku

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


Nested subs are allowed in Perl 6.

sub cube($x) {
Β Β Β  sub square($x) {
Β Β Β Β Β Β Β  return $x * $x;
Β Β Β  }

Β Β Β  return $x * square($x);
}

say cube(3); # 27

The name of the inner sub square is only visible within the body of the outer sub cube.

Leave a Reply

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