Converts Perl data structures into
strings that can be printed or used with eval to
reconstruct the original structures. Takes a list of scalars or
reference variables and writes out their contents in Perl syntax.
Several interfaces to Data::Dumper are provided:
Simple procedural interface:
print Dumper($foo, $bar);
Extended usage with names:
print Data::Dumper->Dump([$foo, $bar], [qw(foo *ary)]);
$d = Data::Dumper->new([$foo, $bar], [qw(foo *ary)]);
By default, references are identified as
$VARn, in which
n is a numeric suffix. References to
$VARn are labeled using
arrow notation. In the extended usage form, references can be given
user-specified names. See the Data::Dumper manpage for examples of
the module's use.
Several configuration variables can be used to control the output
generated using the procedural interface. These variables control the
default state of the object created by the new method. Each variable
has a corresponding method that can be used later to query or modify
the object. In the following list, each variable is followed by the
Can be set to a string that specifies an alternative to the
bless built-in operator used to create objects. A
function with the specified name should exist and should accept the
same arguments as the built-in. Default is bless.
If set to a Boolean value, enables deep copies of structures;
cross-referencing is then done only when absolutely essential.
Default is 0.
Controls the style of indentation for the output. Can be set to:
No newlines, indentation, or spaces between list items
Newlines, but each level in the structure is indented a fixed amount
Default. Takes into account the length of hash keys so the hash
values line up.
Like 2, but also annotates array elements with
their index, with each annotation on its own line
If set to a method name, Data::Dumper invokes that method via the
object before attempting to turn it into a string. Set to an empty
string to disable. Default is empty string.
Specifies the string prefixed to every output line. Default is an
Controls degree to which eval can recreate the
original reference structures. Setting the value to
1 outputs additional Perl statements to correctly
recreate nested references. Default is 0.
If set to a Boolean value, controls whether hash keys are quoted. If
false, avoids quoting hash keys that look like a simple string.
Default is 1, which always quotes hash keys.
When set, Data::Dumper outputs single, non-self-referential values as
atoms or terms rather than as statements.
$VARn names are avoided
as much as possible. Such output may not be parsable by
If set to a method name, Data::Dumper issues a method call for any
objects that will be dumped using the syntax bless(data,
class)->method( ). Set to an empty string to disable.
Default is empty string.
When set, enables the use of double quotes to represent string
values. In addition, \n, \t,
and \r are used to represent non-space whitespace;
"unsafe" characters are
backslashed; and unprintable characters are output as quoted octal
integers. Default is 0. Currently, the
Dumpxs method does not honor this flag.
Specifies the prefix to use for tagging variable names in the output.
Default is VAR.
The following methods and functions are provided.
$obj = Data::Dumper->new(arrayref[, arrayref])
Creates a new Data::Dumper object. The first argument is an anonymous
array of values to be dumped. The optional second argument is an
anonymous array of names for the values. The names
don't need a leading $ and must
be comprised of alphanumeric characters. You can begin a name with a
* to specify that the dereferenced type must be
dumped instead of the reference itself for array and hash references.
Returns stringified form of
values stored in the object with their order preserved, subject to
the configuration options. In array context, returns a list of
strings corresponding to the supplied values.
Function that returns the
stringified form of the values in the list, subject to the
configuration options. The values are named
$VARn in the output.
Returns a list of strings in array context.
Dumper, except that it calls the
xsub implementation. Available only if the
xsub extension to Data::Dumper is installed.
Identical to Dump, but written in C and therefore
much faster. Available only if the xsub extension
to Data::Dumper is installed.
the internal table of "seen"
references, returning the object itself.
Queries or adds to the
internal table of references that have been encountered. The
references aren't dumped, but their names are
inserted when they are encountered subsequently. With no argument,
returns the "seen" list of
name => value pairs, in array context.
Otherwise, returns the object itself.
Queries or replaces the
internal array of values to be dumped. With no arguments, returns the
names. Otherwise, returns the object itself.
Copyright © 2002 O'Reilly & Associates. All rights reserved.