1Data::Dump(3)         User Contributed Perl Documentation        Data::Dump(3)
2
3
4

NAME

6       Data::Dump - Pretty printing of data structures
7

SYNOPSIS

9        use Data::Dump qw(dump);
10
11        $str = dump(@list);
12        @copy_of_list = eval $str;
13
14        # or use it for easy debug printout
15        use Data::Dump; dd localtime;
16

DESCRIPTION

18       This module provide a few functions that traverse their argument and
19       produces a string as its result.  The string contains Perl code that,
20       when "eval"ed, produces a deep copy of the original arguments.
21
22       The main feature of the module is that it strives to produce output
23       that is easy to read.  Example:
24
25           @a = (1, [2, 3], {4 => 5});
26           dump(@a);
27
28       Produces:
29
30           "(1, [2, 3], { 4 => 5 })"
31
32       If you dump just a little data, it is output on a single line. If you
33       dump data that is more complex or there is a lot of it, line breaks are
34       automatically added to keep it easy to read.
35
36       The following functions are provided (only the dd* functions are
37       exported by default):
38
39       dump( ... )
40       pp( ... )
41           Returns a string containing a Perl expression.  If you pass this
42           string to Perl's built-in eval() function it should return a copy
43           of the arguments you passed to dump().
44
45           If you call the function with multiple arguments then the output
46           will be wrapped in parenthesis "( ..., ... )".  If you call the
47           function with a single argument the output will not have the
48           wrapping.  If you call the function with a single scalar (non-
49           reference) argument it will just return the scalar quoted if
50           needed, but never break it into multiple lines.  If you pass
51           multiple arguments or references to arrays of hashes then the
52           return value might contain line breaks to format it for easier
53           reading.  The returned string will never be "\n" terminated, even
54           if contains multiple lines.  This allows code like this to place
55           the semicolon in the expected place:
56
57              print '$obj = ', dump($obj), ";\n";
58
59           If dump() is called in void context, then the dump is printed on
60           STDERR and then "\n" terminated.  You might find this useful for
61           quick debug printouts, but the dd*() functions might be better
62           alternatives for this.
63
64           There is no difference between dump() and pp(), except that dump()
65           shares its name with a not-so-useful perl builtin.  Because of this
66           some might want to avoid using that name.
67
68       quote( $string )
69           Returns a quoted version of the provided string.
70
71           It differs from "dump($string)" in that it will quote even numbers
72           and not try to come up with clever expressions that might shorten
73           the output.  If a non-scalar argument is provided then it's just
74           stringified instead of traversed.
75
76       dd( ... )
77       ddx( ... )
78           These functions will call dump() on their argument and print the
79           result to STDOUT (actually, it's the currently selected output
80           handle, but STDOUT is the default for that).
81
82           The difference between them is only that ddx() will prefix the
83           lines it prints with "# " and mark the first line with the file and
84           line number where it was called.  This is meant to be useful for
85           debug printouts of state within programs.
86
87       dumpf( ..., \&filter )
88           Short hand for calling the dump_filtered() function of
89           Data::Dump::Filtered.  This works like dump(), but the last
90           argument should be a filter callback function.  As objects are
91           visited the filter callback is invoked and it can modify how the
92           objects are dumped.
93

CONFIGURATION

95       There are a few global variables that can be set to modify the output
96       generated by the dump functions.  It's wise to localize the setting of
97       these.
98
99       $Data::Dump::INDENT
100           This holds the string that's used for indenting multiline data
101           structures.  It's default value is "  " (two spaces).  Set it to ""
102           to suppress indentation.  Setting it to "| " makes for nice visuals
103           even if the dump output then fails to be valid Perl.
104
105       $Data::Dump::TRY_BASE64
106           How long must a binary string be before we try to use the base64
107           encoding for the dump output.  The default is 50.  Set it to 0 to
108           disable base64 dumps.
109

LIMITATIONS

111       Code references will be dumped as "sub { ... }". Thus, "eval"ing them
112       will not reproduce the original routine.  The "..."-operator used will
113       also require perl-5.12 or better to be evaled.
114
115       If you forget to explicitly import the "dump" function, your code will
116       core dump. That's because you just called the builtin "dump" function
117       by accident, which intentionally dumps core.  Because of this you can
118       also import the same function as "pp", mnemonic for "pretty-print".
119

HISTORY

121       The "Data::Dump" module grew out of frustration with Sarathy's in-most-
122       cases-excellent "Data::Dumper".  Basic ideas and some code are shared
123       with Sarathy's module.
124
125       The "Data::Dump" module provides a much simpler interface than
126       "Data::Dumper".  No OO interface is available and there are fewer
127       configuration options to worry about.  The other benefit is that the
128       dump produced does not try to set any variables.  It only returns what
129       is needed to produce a copy of the arguments.  This means that
130       "dump("foo")" simply returns '"foo"', and "dump(1..3)" simply returns
131       '(1, 2, 3)'.
132

SEE ALSO

134       Data::Dump::Filtered, Data::Dump::Trace, Data::Dumper, JSON, Storable
135

AUTHORS

137       The "Data::Dump" module is written by Gisle Aas <gisle@aas.no>, based
138       on "Data::Dumper" by Gurusamy Sarathy <gsar@umich.edu>.
139
140        Copyright 1998-2010 Gisle Aas.
141        Copyright 1996-1998 Gurusamy Sarathy.
142
143       This library is free software; you can redistribute it and/or modify it
144       under the same terms as Perl itself.
145
146
147
148perl v5.30.1                      2020-01-29                     Data::Dump(3)
Impressum