Course of Raku / Advanced /
Debugging / Debugging with dd / Exercises / Dump the data
structure
Solution: Dump the data structure
Here is a possible solution to the task.
Code
my @data = 'Raku', [1, 2, 3], (key => 'value');
dd @data;
say "Structure: { @data.raku }";🦋 You can find the source code in the file dump-the-structure.raku.
Output
["Raku", [1, 2, 3], :key("value")]
Structure: ["Raku", [1, 2, 3], :key("value")]Comments
dd @dataprints a code-like representation of the contents of the array. It goes to the standard error stream.The
.rakumethod returns the same representation as a string, which is then embedded into a normal message using code interpolation and printed withsayto the standard output.The two lines look the same here, but they travel through different output streams: the first comes from
dd(standard error), the second fromsay(standard output). Compare the following:
$ raku t.raku > /dev/null
["Raku", [1, 2, 3], :key("value")]
$ raku t.raku 2&> /dev/null
Structure: ["Raku", [1, 2, 3], :key("value")]