Course of Raku / Essentials / More about types / Data type conversion
Introspection with
WHAT
It is possible to see the type of data in a variable by calling the
WHAT method on it:
my $n = 42;
my $s = '42';
say $n.WHAT; # (Int)
say $s.WHAT; # (Str)The type is printed in parentheses, as shown in the comments. For
example, (Int) or (Str).
There is no problem calling a method on a literal itself. For example:
say 42.WHAT; # (Int)
say (-1).WHAT; # (Int)
say 'Hello'.WHAT; # (Str)
say True.WHAT; # (Bool)Notice that in the case of -1, we put the number in
parentheses, as say -1.WHAT would try to negate the result
of 1.WHAT, which leads to an exception.
Practice
Complete the quiz that covers the contents of this topic.
Course navigation
← Data type conversion | Quiz: What does WHAT return? →
💪 Or jump directly to the exercises in this
section.
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська