I am using Data::Dumper::Dumper()
method. The output is good, but can be made little compact and more good looking.
How I can control it? What are the better alternatives?
I am using Data::Dumper::Dumper()
method. The output is good, but can be made little compact and more good looking.
How I can control it? What are the better alternatives?
One option is to use Data::Dumper::Perltidy which is a (more or less) drop-in replacement for Data::Dumper::Dumper() but which uses Perltidy to format the output.
Data::Dumper::Concise is another possibility.
is equivalent to:
If you're just looking for dump output:
Smart::Comments
.You just
use
it.And then you put any simple variable in a three-hash comment, like so:
And it dumps it out in almost the prettiest print possible.
You can also manage more complex expressions like so:
But you have to watch it for "colon paths".
or
### %My::Package::
has never worked in my experience. If I want them to work then I need something like this:
It also does a number of other cute tricks, which you can see if you read the documentation.
If you want to serialize output for storage (rather than for display), take a look at Storable's
freeze()
andthaw()
. I cringe whenever I see Data::Dumper being used to save data structures in a DB or cache. :(One alternative* to Data::Dumper would be JSON and its Perl implementation JSON.
* Whether it is better is up to you to decide.
Take a look at Data::Dump for something similar to Data::Dumper but arguably better at pretty printing.
Edit (20120304): I had completely forgotten this question, but it was upvoted today and that jogged my memory. If I had to recommend anything today (3 years later) for pretty printing in Perl, I would certainly go with Data::Printer. From Data::Printer's own Rationale: