Dumpxs#
Serialize one or more values into valid Perl code, fast.
Dumpxs and Dump take the same arguments and produce the same output; Dumpxs is the faster of the two, and Dump delegates here unless $Data::Dumper::Useperl is true.
Synopsis#
use Data::Dumper;
print Data::Dumper->new([\%h, \@a], ['hash', 'array'])->Dumpxs;
print Data::Dumper::Dumpxs('Data::Dumper', [\%h], ['hash']);
What you get back#
In scalar context, a single string containing one $VAR = ...; statement per input value, separated by $self->{sep} (default "\n"). In list context, one string per input - useful when you want to post-process each dump separately.
With Terse(1), the $VAR = prefix and trailing ; are dropped and you get a bare Perl expression suitable for embedding.
Examples#
Named output, default formatting:
my %h = (a => 1, b => [2, 3]);
print Data::Dumper->new([\%h], ['h'])->Dumpxs;
# $h = {
# 'a' => 1,
# 'b' => [2, 3]
# };
Compact, sorted, double-quoted:
print Data::Dumper->new([\%h])
->Indent(0)->Sortkeys(1)->Useqq(1)->Dumpxs;
# $VAR1 = {"a" => 1,"b" => [2,3]};
Circular structure - the cycle is emitted as a backref, not an infinite expansion:
my @a = (1, 2);
push @a, \@a;
print Data::Dumper->new([\@a])->Dumpxs;
# $VAR1 = [1, 2, $VAR1];
List context gives you one string per argument:
my ($s1, $s2) = Data::Dumper->new([\%h, \@a])->Dumpxs;
Edge cases#
First argument is not a blessed hashref:
Dumpxswill callnew()internally using the remaining arguments, soData::Dumper::Dumpxs('Data::Dumper', \@vals, \@names)works.maxrecurseexceeded: croaks with"Recursion limit of N exceeded"after finishing the current top-level value so partial output is not lost from the caller’s perspective.maxdepthexceeded: prints the quoted stringification of the ref (e.g.'ARRAY(0x...)') at the cut-off point rather than croaking.CODEreferences: emitted assub { "DUMMY" }unlessDeparse(1)is set, in which case the deparsed source is emitted.Regexp references: emitted as
qr/.../flags.Sortkeysas a coderef: called once per hash to obtain the key order; a truthy non-coderef sorts alphabetically.
See also#
Dump- the pure-Perl fallback; identical output, slower.Dumper- the procedural one-liner wrappingnew(...)->Dumpxs.Seen- pre-seed the seen-table to name pre-existing references.Reset- clear the seen-table between unrelatedDumpxscalls.