Data::Dumper#

📦 std

Stringify Perl data structures into valid Perl code — feed the result back through eval and you rebuild the original structure.

Two calling styles cover almost everything:

  • Functional: Dumper(\%h, \@a) — one call, one string, uses the package-global configuration variables ($Data::Dumper::Indent etc.).

  • Object-oriented: Data::Dumper->new([\%h, \@a], ['hash', 'array']) returns a configurable dumper object. Chain accessors to tune output, then call ->Dump to produce the string.

The main knobs:

  • $Indent0 compact, 1 line-wrapped, 2 line-wrapped with alignment (the default and the most readable).

  • $Purity — when true, round-trip fidelity for self-referential and cyclic structures at the cost of extra fixup statements.

  • $Sortkeys1 for alphabetical, or a coderef returning the key order per hash.

  • $Deepcopy — break shared references and emit each one as a copy.

  • $Terse — omit the $VAR1 = prefix; emits a bare expression.

  • $Useqq — quote strings with "" and visible escapes (\n, \t, \x{...}) instead of '...'.

  • $Sparseseen — skip populating the internal “seen” hash for values that the dumper can prove are never revisited. Trades memory for a small amount of safety on bizarre inputs.

Cycles and shared references are tracked through an internal seen table keyed by referent address; a second visit prints as a backref like $VAR1->[0] instead of recursing forever.

Most of the user-facing surface (new, Dump, Reset, Seen, Values, Names, all configuration accessors, import) lives in Dumper.pm and loads from disk; this file provides the two routines that must be written in Rust: the heavy-lifting serializer Dumpxs and the vstring magic probe _vstring.

Functions#

Core API#

dumpxs#

Serialize one or more values into valid Perl code, fast.

Introspection#

vstring#

Return the raw bytes of a v-string, or undef if the argument is not a v-string.