Basics · lesson 2 of 18
Variables
Declare variables with my; scalars use the $ sigil and interpolate into strings.
Variables are declared with my. A single value — a number, a string, anything that is one thing — lives in a variable with the $ sigil:
my $name = 'Alice'; my $age = 30; say $name; say $age;
Output
Alice
30The sigil stays part of the name: it's $name when you declare it, assign to it, and read it. (Raku also has @ for arrays and % for hashes — those get their own lessons soon.)
Interpolation #
Double-quoted strings interpolate variables directly:
my $name = 'Alice'; say "Hello, $name!"; say 'Hello, $name!';
Output
Hello, Alice!
Hello, $name!Single quotes keep the text literal — a useful pair to remember.
Variables vary #
Assignment with = replaces the value; operators like += and ~= (string append) update it in place.
my $count = 10; $count = $count + 5; $count += 5; say $count; my $word = 'Ra'; $word ~= 'ku'; say $word;
Output
20
RakuTry it #
Declare a variable holding your favourite language and print I like <language>! using interpolation.
my $language = ...;
Show a solution
my $language = 'Raku'; say "I like $language!";
Output
I like Raku!