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)]);
Object-oriented interface:
$d = Data::Dumper->new([$foo, $bar], [qw(foo *ary)]); ... print $d->Dump;
By default, references are identified as $VARn, in which n is a numeric suffix. References to substructures within $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 corresponding method:
The following methods and functions are provided.
new |
$obj = Data::Dumper->new(arrayref[, arrayref])
Constructor. 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.
Dump |
$obj->Dump Data::Dumper->Dump(arrayref[, arrayref]) |
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.
Dumper |
Dumper (list)
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.
DumperX |
DumperX (list)
Identical to Dumper, except that it calls the xsub implementation. Available only if the xsub extension to Data::Dumper is installed.
Dumpxs |
$obj->Dumpxs Data::Dumper->Dumpxs(arrayref[, arrayref]) |
Identical to Dump, but written in C and therefore much faster. Available only if the xsub extension to Data::Dumper is installed.
Seen |
$obj->Seen([hashref])
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.
Values |
$obj->Values([arrayref])
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.