In Perl I need to analyze a huge hash, so I print it into a file using Data::Dumper
module. Because it is a huge file, it is very hard to read. Is it possible somehow to print Dumper
output nicely, so when I will find a string that I am looking for, I will be able to see immediately key structure where the string I am looking for is stored?
Currently I am using just a simple code:
use Data::Dumper;
...
print Dumper $var;
What is the best syntax or alternative to get nice output?
I almost always set
$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;
with Data::Dumper
. The first statement makes the output more compact and much more readable when your data structure is several levels deep. The second statement makes it easier to scan the output and quickly find the keys you are most interested in.
If the data structure contains binary data or embedded tabs/newlines, also consider
$Data::Dumper::Useqq = 1;
which will output a suitable readable representation for that data.
Much more in the perldoc.