Course of Raku / Essentials / More about types / Associative data types

Interpolating hashes

To interpolate hash 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

Quiz — Multilevel hashes   |   Quiz — Interpolating hashes


💪 Or jump directly to the exercises in this section.

Translations of this page: EnglishDeutschEspañolItalianoLatviešuNederlandsБългарскиРусскийУкраїнська