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?
There are tons of options to Data::Dumper. See the documentation. You can fix indentation, padding, variable names, depth, key sorting, etc.
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.
I normally use Data::Dump::Streamer, but as the others said, only when the options to Data::Dumper aren't enough.
If you're just looking for dump output: Smart::Comments
.
You just use
it.
use Smart::Commments;
And then you put any simple variable in a three-hash comment, like so:
my $v = black_box_process();
### $v
And it dumps it out in almost the prettiest print possible.
You can also manage more complex expressions like so:
### ( $a && ( $b ^ ( $c || $d ))) : ( $a && ( $b ^ ( $c || $d )))
But you have to watch it for "colon paths".
### $My::Package::variable
or
### %My::Package::
has never worked in my experience. If I want them to work then I need something like this:
my %stash = %My::Package::;
### %stash
It also does a number of other cute tricks, which you can see if you read the documentation.
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.