```{index} single: dumpxs; Data::Dumper function ``` ```{index} single: Data::Dumper::dumpxs; Perl function ``` # dumpxs Serialize one or more values into valid Perl code, fast. `Dumpxs` is the XS counterpart of `Dump`: same inputs, same output, implemented without the pure-Perl recursion overhead. `Dump` itself delegates here unless `$Data::Dumper::Useperl` is true. ## Synopsis ```perl 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: ```perl my %h = (a => 1, b => [2, 3]); print Data::Dumper->new([\%h], ['h'])->Dumpxs; ## $h = { ## 'a' => 1, ## 'b' => [2, 3] ## }; ``` Compact, sorted, double-quoted: ```perl 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: ```perl 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: ```perl my ($s1, $s2) = Data::Dumper->new([\%h, \@a])->Dumpxs; ``` ## Edge cases - First argument is not a blessed hashref: `Dumpxs` will call `new()` internally using the remaining arguments, so `Data::Dumper::Dumpxs('Data::Dumper', \@vals, \@names)` works. - `maxrecurse` exceeded: 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. - `maxdepth` exceeded: prints `[...]` or `{...}` at the cut-off point rather than croaking. - `CODE` references: emitted as `sub { "DUMMY" }` unless `Deparse(1)` is set. - Regexp references: emitted as `qr/.../`. - `Sortkeys` as a coderef: accepted but currently treated as a truthy value, i.e. alphabetical sort. The coderef is not invoked. ## Differences from upstream - `Sortkeys` as a coderef: upstream calls the coderef per hash to obtain a custom key order; pperl treats any truthy `Sortkeys` as alphabetical. Scripts relying on coderef ordering need to pre-sort their data or call `Dump` with `Useperl(1)`. - `Deparse(1)` emits `sub { "DUMMY" }` instead of the deparsed source. Scripts that depend on round-tripping closures need `Useperl(1)`. - `Purity(1)` is accepted and stored but does not yet emit the post-dump fixup statements upstream produces for self-referential structures; the backref notation works but arbitrary in-place assignments to reach an already-seen inner value are not emitted. ## See also - `Dump` — the pure-Perl fallback; identical output, slower. - `Dumper` — the procedural one-liner wrapping `new(...)->Dumpxs`. - `Seen` — pre-seed the seen-table to name pre-existing references. - `Reset` — clear the seen-table between unrelated `Dumpxs` calls.