Drinking the Data::Printer Kool-Aid

A long-time user of Data::Dumper, here. I have seen several talks about using Data::Printer in cases when you want the output to be readable by humans, not machines. I've always meant to eventually get around to checking it out. Today was that day.

I had a huge data structure at work, nested many layers deep and full of repetition with slight variances. My job was to find out what was wrong with it. After looking at the Dumper output for about 10 minutes, I became aware that I had actually stopped looking at the Dumper output a few minutes prior and my mind had wandered somewhere else (squirrel!) So, I decided to see if Data::Printer made the job any easier.

The first challenge was getting the module to install. Using cpanm, I was able to get it to install with just three tries and 44 dependencies to install. (By the way, DateTime::Duration, and Digest::MD4 are both undocumented dependencies somewhere along that dependency tree, don't ask me where.)

After that, I found that Data::Printer made the simple, simple. Dumping an object is very simple:

p $obj;

With with power comes complexity, however. Data::Printer has a lot of stuff that you can configure. Way more than I wanted to read about to accomplish my simple project. But at least the simple stuff was easy, and that's enough to get me past day 1 and make me want to learn more about it later.


I'd suggest you write a wrapper providing settings for various 'basic' options.

See that great module Data::Dumper::Concise for how this was done for that other great module Data::Dumper.

You might thereby make Data::Printer more approachable, although after your installation saga, I have my doubts :-(.

When I get in those situations, I start building special methods into the class so I can control precisely how I get to see the data structure (as well as modify the method for special cases).

Some modules (like some of the JSON ones) look for special method names in the object's classes. I've meant for a long time to do a survey of those.

Leave a comment

About Dan Wright

user-pic I'm the Treasurer for The Perl Foundation and Team Leader for YAPC::NA. I have organized Perl events including 7 Pittsburgh Perl Workshops and two YAPC::NA's. In my day job, I'm the director of technical operations for pairNIC.com. I write code and I supervise a team of Perl developers.