Last Updated: February 25, 2016
·
1.047K
· kablamo

I finally switched to Data::Printer

The recent explosion of Perl libraries for dumping data (Data::Dump, Data::Dump::Streamer, Data::PrettyPrintObjects, Data::Dumper, Data::Dumper::Concise, Data::TreeDumper, etc, etc.) overwhelmed me and I tuned it all out for a long time.

The main reason I finally switched to Data::Printer is it's really short to type. So instead of

use Data::Dumper::Concise; print Dumper $foo;

I could just type

use DDP; p $foo;

But after using it for a while I noticed a second awesome thing: I don't have to pass in a reference. I can pass in arrays or scalars and it figures it out for me.

Soon after I discovered a third awesome thing: filters. If you have a big data structure which includes database objects and DateTime objects, most dumpers will dump all the details of these giant objects giving you so much output that its unreadable. But you can configure Data::Printer to stringify your DateTime objects and shutup about all the internals. Same for db objects.

And fourthly filters would be dumb if you had to type all that everytime, but happily you can create a config file. Here is mine: ~/.datadumper.

1 Response
Add your response

You could always add hooks to skip unreadable output with Data::Dumper ($Data::Dumper::Freezer), but this looks simpler

over 1 year ago ·