Data::Dumper::Perltidy - Dump and pretty print Perl data structures.
To use Data::Dumper::Perltidy::Dumper() to stringify and pretty print a Perl data structure:
Data::Dumper::Perltidy::Dumper()
use Data::Dumper::Perltidy; ... print Dumper $some_data_structure;
Data::Dumper::Perltidy encapsulates both Data::Dumper and Perl::Tidy to provide a function that stringifies a Perl data structure in a pretty printed format. See the documentation for Data::Dumper and Perl::Tidy for further information.
Data::Dumper::Perltidy
Data::Dumper
Perl::Tidy
Data::Dumper can be used for, among other things, stringifying complex Perl data structures into a format that is suitable for printing and debugging.
Perl::Tidy can be used to pretty print Perl code in a consistent and configurable manner.
Data::Dumper also provides a certain level of pretty printing via the $Data::Dumper::Indent variable but it isn't quite as nice as the Perl::Tidy output.
$Data::Dumper::Indent
Let's look at an example to see how this module can be used. Say you have a complex data structure that you wish to inspect. You can use the Data::Dumper::Perltidy::Dumper() function as follows (note that the syntax is the same as Data::Dumper):
#!/usr/bin/perl -w use strict; use Data::Dumper::Perltidy; my $data = [{ title => 'This is a test header' },{ data_range => [ 0, 0, 3, 9 ] },{ format => 'bold' }]; print Dumper $data;
This would print out:
$VAR1 = [ { 'title' => 'This is a test header' }, { 'data_range' => [ 0, 0, 3, 9 ] }, { 'format' => 'bold' } ];
By comparison the standard Data::Dumper::Dumper() output would be:
Data::Dumper::Dumper()
Which isn't too bad but if you are used to Perl::Tidy and the perltidy utility you may prefer the Data::Dumper::Perltidy::Dumper() output.
The Dumper() function takes a list of perl structures and returns a stringified and pretty printed form of the values in the list. The values will be named $VARn in the output, where n is a numeric suffix.
Dumper()
$VARn
n
You can modify the Perl::Tidy output by passing arguments via the $Data::Dumper::Perltidy::ARGV configuration variable:
$Data::Dumper::Perltidy::ARGV
$Data::Dumper::Perltidy::ARGV = '-nst -mbl=2 -pt=0 -nola';
See the Perl::Tidy docs for more information on the available arguments. By default Data::Dumper::Perltidy uses the argument -npro to ignore any local .perltidyrc configuration file.
-npro
.perltidyrc
The Data::Dumper $Data::Dumper:: configuration variables can also be used to influence the output where applicable. For further information see the Data::Dumper documentation.
$Data::Dumper::
Note: unlike Data::Dumper::Dumper() this function doesn't currently return a list of strings in a list context.
I frequently found myself copying the output of Data::Dumper::Dumper() into an editor so that I could run perltidy on it. This module scratches that itch.
perltidy
This module doesn't attempt to implement all, or even most, of the functionality of Data::Dumper.
John McNamara <jmcnamara@cpan.org>
<jmcnamara@cpan.org>
Please report any bugs or feature requests to https://github.com/jmcnamara/data-dumper-perltidy/issues on Github.
The authors and maintainers of Data::Dumper and Perl::Tidy.
Data::Dump
Data::Printer, which also has a full list of alternatives.
Copyright 2009-2012 John McNamara, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Data::Dumper::Perltidy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Dumper::Perltidy
CPAN shell
perl -MCPAN -e shell install Data::Dumper::Perltidy
For more information on module installation, please visit the detailed CPAN module installation guide.