Course of Raku / Advanced / Modules / Modules basics / Exercises / Use the converter

Solution: Use the converter

Here is a possible solution to the task.

Code

The program, temperature.raku:

use Temperature;

sub MAIN($celsius) {
    say c-to-f($celsius);
}

🦋 You can find both source files in the exercises/advanced/modules-basics/use-temperature directory.

Output

$ raku -I. temperature.raku 100
212

Comments

  1. use Temperature loads the module and imports its exported c-to-f subroutine, so the program can call it directly.

  2. sub MAIN($celsius) receives the command-line argument, so the temperature to convert is chosen when the program is run rather than hard-coded. Run without an argument, Raku prints a usage message automatically.

  3. The module must be reachable, which is why the program is run with -I. so that Raku looks for Temperature.rakumod in the current directory. The conversion of 100 °C gives 212 °F.

Course navigation

Use the converter   |   Use a stats module