Quick Tip #6: Data dumping is built into Rakudo

I’ve often wished that Perl 5’s Data::Dumper was built into the language. I often have statements like:

Dumper( @array ); use Data::Dumper;

Or, if I’m playing with Mojolicious:

use Mojo::Util qw(dumper);
dumper( @array );

Rakudo (one of the Perl 6 implementations) has this baked in as dd. This is something extra beyond the Perl 6 specification. Here I drop into the REPL:

$ perl6
> my @array = 'a' .. 'g'
[a b c d e f g]
> dd @array
Array @array = ["a", "b", "c", "d", "e", "f", "g"]

There is also the gist and perl methods. The first gives you output designed for people and the second shows the actual Perl interpretation:

> @array.gist
[a b c d e f g]
> @array.perl
["a", "b", "c", "d", "e", "f", "g"]

If that’s not enough for you, there’s the Data::Dump module that can do many other things, including colorizing the output.


  1. You don’t really have to know about the `gist` method: `say $something` actually prints `$something.gist` followed by a newline. (If you want output for computers instead of people, use `put`.)

    1. Sounds like there are, again, many ways to do the same thing which makes it hard for newcomers (and we are newcomers, even from Perl 5) to know which one to use.
      What’s the preferred way? Has dd an advantage over .gist?

      1. To talk about advantages, you have to know the goal. .gist is Perl 6, dd is a Rakudo enhancement. Try them and chose the one that you like.

Leave a Reply

Your email address will not be published. Required fields are marked *