πŸ“˜ The need keyword to use a module in Perl 6

πŸ“˜ The need keyword to use a module in Raku

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


To just load a module and do no exports, use the need keyword.

Let us create a module named N, which contains the sub n(). This time, the sub is declared as our but with no is export.

unit module N;Β 

our sub n() {
Β Β Β  say "N::n()";
}

Then you need a module and may use its methods using the fully qualified names.

need N;
N::n();

The sequence of the two instructions: need M; import M; (now import should always come after the need) is equivalent to a single use M; statement.

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