Course of Raku / Essentials / Variables and data types essentials / Scalar variables / Exercises / Greet a person
Solution: Greet a person
Here is a possible solution to the task.
Code
my $name = prompt 'What is your name? ';
say 'Hello, ', $name, '!';🦋 You can find the source code in the file greet-a-person.raku.
Output
Run the program and enter a name when you get the prompt:
$ raku exercises/scalar-variables/greet-a-person.raku
What is your name? Inge
Hello, Inge!Comments
This program uses a scalar variable
$nameto keep a string that was entered by the user in response to the prompt. When the variable is used in the list that you pass to thesayroutine, you get the name in a message.There is a better way to solve this problem using string interpolation. Let us return to this problem shortly.
Course navigation
← Greet a person | The answer to life, the Universe and everything →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська