📘 Modules import summary in Perl 6

Here is a concise list of the keywords for working with modules. use loads and imports a module at compile time need loads a module at compile time but does not import anything from it import imports the names from the loaded module at compile time require loads a module at runtime without importing the … Continue reading “📘 Modules import summary in Perl 6”

📘 Creating a module in Perl 6

The keyword module declares a module. The name of the module is given after the keyword. There are two methods of scoping the module. Either it can be a bare directive in the beginning of a file, or the whole module can be scoped in the code block within the pair of braces. In the … Continue reading “📘 Creating a module in Perl 6”

📘 Using a module in Perl 6

To use a module in your code, use the keyword use. An example. Let us first create the module Greet and save it in the file named Greet.pm. unit module Greet;  sub hey($name) is export {     say “Hey, $name!”; } Then, let us use this module in our programme by saying use Greet. use … Continue reading “📘 Using a module in Perl 6”

📘 Importing a module in Perl 6

The use keyword automatically imports the names from modules. When a module is defined in the current file in the lexical scope (please note that the module can be declared as local with my module), no import will be done by default. In this case, importing the names should be done explicitly with the import … Continue reading “📘 Importing a module in Perl 6”

📘 The require keyword to use a module in Perl 6

The require keyword loads a module at a runtime unlike the use, which loads it at the compile-time. For example, here is a module with a single sub, which returns the sum of its arguments. unit module Math;  our sub sum(*@a) {     return [+] @a; } (The star in *@a is required to tell … Continue reading “📘 The require keyword to use a module in Perl 6”