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 ddx);
10
11        $str = dump(@list);
12        @copy_of_list = eval $str;
13
14        # or use it for easy debug printout
15        ddx localtime;
16

DESCRIPTION

18       This module provide functions that takes a list of values as their
19       argument and produces a string as its result.  The string contains Perl
20       code that, when "eval"ed, produces a deep copy of the original
21       arguments.
22
23       The main feature of the module is that it strives to produce output
24       that is easy to read.  Example:
25
26           @a = (1, [2, 3], {4 => 5});
27           dump(@a);
28
29       Produces:
30
31           (1, [2, 3], { 4 => 5 })
32
33       If you dump just a little data, it is output on a single line. If you
34       dump data that is more complex or there is a lot of it, line breaks are
35       automatically added to keep it easy to read.
36
37       The following functions are provided (only the dd* functions are
38       exported by default):
39
40       dump( ... )
41       pp( ... )
42           Returns a string containing a Perl expression.  If you pass this
43           string to Perl's built-in eval() function it should return a copy
44           of the arguments you passed to dump().
45
46           If you call the function with multiple arguments then the output
47           will be wrapped in parenthesis "( ..., ... )".  If you call the
48           function with a single argument the output will not have the
49           wrapping.  If you call the function with a single scalar (non-
50           reference) argument it will just return the scalar quoted if
51           needed, but never break it into multiple lines.  If you pass
52           multiple arguments or references to arrays of hashes then the
53           return value might contain line breaks to format it for easier
54           reading.  The returned string will never be "\n" terminated, even
55           if contains multiple lines.  This allows code like this to place
56           the semicolon in the expected place:
57
58              print '$obj = ', dump($obj), ";\n";
59
60           If dump() is called in void context, then the dump is printed on
61           STDERR and then "\n" terminated.  You might find this useful for
62           quick debug printouts, but the dd*() functions might be better
63           alternatives for this.
64
65           There is no difference between dump() and pp(), except that dump()
66           shares its name with a not-so-useful perl builtin.  Because of this
67           some might want to avoid using that name.
68
69       quote( $string )
70           Returns a quoted version of the provided string.
71
72           It differs from "dump($string)" in that it will quote even numbers
73           and not try to come up with clever expressions that might shorten
74           the output.
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

LIMITATIONS

88       Code references will be displayed as simply 'sub { "???" }' when
89       dumped. Thus, "eval"ing them will not reproduce the original routine.
90
91       If you forget to explicitly import the "dump" function, your code will
92       core dump. That's because you just called the builtin "dump" function
93       by accident, which intentionally dumps core.  Because of this you can
94       also import the same function as "pp", mnemonic for "pretty-print".
95

HISTORY

97       The "Data::Dump" module grew out of frustration with Sarathy's in-most-
98       cases-excellent "Data::Dumper".  Basic ideas and some code are shared
99       with Sarathy's module.
100
101       The "Data::Dump" module provides a much simpler interface than
102       "Data::Dumper".  No OO interface is available and there are no
103       configuration options to worry about (yet :-).  The other benefit is
104       that the dump produced does not try to set any variables.  It only
105       returns what is needed to produce a copy of the arguments.  This means
106       that "dump("foo")" simply returns "foo", and "dump(1..5)" simply
107       returns "(1, 2, 3, 4, 5)".
108

SEE ALSO

110       Data::Dumper, Storable
111

AUTHORS

113       The "Data::Dump" module is written by Gisle Aas <gisle@aas.no>, based
114       on "Data::Dumper" by Gurusamy Sarathy <gsar@umich.edu>.
115
116        Copyright 1998-2000,2003-2004,2008 Gisle Aas.
117        Copyright 1996-1998 Gurusamy Sarathy.
118
119       This library is free software; you can redistribute it and/or modify it
120       under the same terms as Perl itself.
121
122
123
124perl v5.12.0                      2009-07-26                     Data::Dump(3)
Impressum