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
FR	Paris
IT	Rome

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


Complete the quiz that covers the contents of this topic.

Course navigation

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

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