Perl 6 has data dumping built in

| 3 Comments

Any Perl 5 programmer who's worked with Perl 5 more than a few months has learned about how invaluable the Data::Dumper module is. The ability to say

use Data::Dumper;
print Dumper( \%hash );

is a godsend to debugging data structures of any complexity.

Perl 6 has this dumping built in.

uniqua:~/rakudo/lab $ cat dumper
#!/usr/local/bin/perl6

use v6;

my %hash = (
    'this'     => 'that',
    'year'     => 2112,
    'matcher'  => regex { ^ M(r|rs|s)\. \s+ (\w+) \s+ Wall $ },
    'rational' => 0.5,
    'num'      => (0.5).Num,
);

say %hash.perl;
# Or %hash.perl.say

uniqua:~/rakudo/lab $ ./dumper
{"num" => 0.5, "this" => "that", "year" => 2112,
"rational" => 1/2, "matcher" => { ... }}

Regex dumping does not display the actual regex yet, but Patrick Michaud says it's coming soon.

3 Comments

Perl5 also had this built in. Just use the debugger and type x \%hash. Then you don't have to put in Data::Dumper and print statements and then have to take them out.

That is of course if your application lends itself to easy debugging, otherwise I'd happily go with say %hash.perl.

How do we format it?
Perl5 was something like:
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;

Leave a comment

Job hunting for programmers


Land the Tech Job You Love, Andy Lester's guide to job hunting for programmers and other technical professionals, is available in PDF, ePub and .mobi formats, all DRM-free, as well as good old-fashioned paper.

Contact