Course of Raku / Essentials / Associative data types

Interpolating hashes

To interpolate array elements in double-quoted strings spell them as you do in the program itself: %data<FR>. To interpolate the whole hash, add a pair of empty angles or curly brackets: @data{}. The following program illustrates this approach:

my %data = FR => 'Paris', IT => 'Rome';

say "%data<FR>";
say "%data<>";

# Or:
# say "%data{}";

This program prints the requested data:

$ raku t.raku
Paris
FR	Paris
IT	Rome

Note that printing the whole hash may generate multi-line output.

Practice

Complete the quiz that covers the contents of this topic.

Course navigation

Associative data types / Nested hashes   |   💪 Exercises: Associative data types