<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#
# Data/Dumper.pm
#
# convert perl data structures into perl syntax suitable for both printing
# and eval
#
# Documentation at the __END__
#

package Data::Dumper;

BEGIN {
    $VERSION = '2.174'; # Don't forget to set version and release
}               # date in POD below!

#$| = 1;

use 5.006_001;
require Exporter;

use constant IS_PRE_516_PERL =&gt; $] &lt; 5.016;

use Carp ();

BEGIN {
    @ISA = qw(Exporter);
    @EXPORT = qw(Dumper);
    @EXPORT_OK = qw(DumperX);

    # if run under miniperl, or otherwise lacking dynamic loading,
    # XSLoader should be attempted to load, or the pure perl flag
    # toggled on load failure.
    eval {
        require XSLoader;
        XSLoader::load( 'Data::Dumper' );
        1
    }
    or $Useperl = 1;
}

my $IS_ASCII  = ord 'A' ==  65;

# module vars and their defaults
$Indent     = 2         unless defined $Indent;
$Trailingcomma = 0      unless defined $Trailingcomma;
$Purity     = 0         unless defined $Purity;
$Pad        = ""        unless defined $Pad;
$Varname    = "VAR"     unless defined $Varname;
$Useqq      = 0         unless defined $Useqq;
$Terse      = 0         unless defined $Terse;
$Freezer    = ""        unless defined $Freezer;
$Toaster    = ""        unless defined $Toaster;
$Deepcopy   = 0         unless defined $Deepcopy;
$Quotekeys  = 1         unless defined $Quotekeys;
$Bless      = "bless"   unless defined $Bless;
#$Expdepth   = 0         unless defined $Expdepth;
$Maxdepth   = 0         unless defined $Maxdepth;
$Pair       = ' =&gt; '    unless defined $Pair;
$Useperl    = 0         unless defined $Useperl;
$Sortkeys   = 0         unless defined $Sortkeys;
$Deparse    = 0         unless defined $Deparse;
$Sparseseen = 0         unless defined $Sparseseen;
$Maxrecurse = 1000      unless defined $Maxrecurse;

#
# expects an arrayref of values to be dumped.
# can optionally pass an arrayref of names for the values.
# names must have leading $ sign stripped. begin the name with *
# to cause output of arrays and hashes rather than refs.
#
sub new {
  my($c, $v, $n) = @_;

  Carp::croak("Usage:  PACKAGE-&gt;new(ARRAYREF, [ARRAYREF])")
    unless (defined($v) &amp;&amp; (ref($v) eq 'ARRAY'));
  $n = [] unless (defined($n) &amp;&amp; (ref($n) eq 'ARRAY'));

  my($s) = {
        level      =&gt; 0,           # current recursive depth
        indent     =&gt; $Indent,     # various styles of indenting
        trailingcomma =&gt; $Trailingcomma, # whether to add comma after last elem
        pad        =&gt; $Pad,        # all lines prefixed by this string
        xpad       =&gt; "",          # padding-per-level
        apad       =&gt; "",          # added padding for hash keys n such
        sep        =&gt; "",          # list separator
        pair       =&gt; $Pair,    # hash key/value separator: defaults to ' =&gt; '
        seen       =&gt; {},          # local (nested) refs (id =&gt; [name, val])
        todump     =&gt; $v,          # values to dump []
        names      =&gt; $n,          # optional names for values []
        varname    =&gt; $Varname,    # prefix to use for tagging nameless ones
        purity     =&gt; $Purity,     # degree to which output is evalable
        useqq      =&gt; $Useqq,      # use "" for strings (backslashitis ensues)
        terse      =&gt; $Terse,      # avoid name output (where feasible)
        freezer    =&gt; $Freezer,    # name of Freezer method for objects
        toaster    =&gt; $Toaster,    # name of method to revive objects
        deepcopy   =&gt; $Deepcopy,   # do not cross-ref, except to stop recursion
        quotekeys  =&gt; $Quotekeys,  # quote hash keys
        'bless'    =&gt; $Bless,    # keyword to use for "bless"
#        expdepth   =&gt; $Expdepth,   # cutoff depth for explicit dumping
        maxdepth   =&gt; $Maxdepth,   # depth beyond which we give up
	maxrecurse =&gt; $Maxrecurse, # depth beyond which we abort
        useperl    =&gt; $Useperl,    # use the pure Perl implementation
        sortkeys   =&gt; $Sortkeys,   # flag or filter for sorting hash keys
        deparse    =&gt; $Deparse,    # use B::Deparse for coderefs
        noseen     =&gt; $Sparseseen, # do not populate the seen hash unless necessary
       };

  if ($Indent &gt; 0) {
    $s-&gt;{xpad} = "  ";
    $s-&gt;{sep} = "\n";
  }
  return bless($s, $c);
}

# Packed numeric addresses take less memory. Plus pack is faster than sprintf

# Most users of current versions of Data::Dumper will be 5.008 or later.
# Anyone on 5.6.1 and 5.6.2 upgrading will be rare (particularly judging by
# the bug reports from users on those platforms), so for the common case avoid
# complexity, and avoid even compiling the unneeded code.

sub init_refaddr_format {
}

sub format_refaddr {
    require Scalar::Util;
    pack "J", Scalar::Util::refaddr(shift);
};

if ($] &lt; 5.008) {
    eval &lt;&lt;'EOC' or die;
    no warnings 'redefine';
    my $refaddr_format;
    sub init_refaddr_format {
        require Config;
        my $f = $Config::Config{uvxformat};
        $f =~ tr/"//d;
        $refaddr_format = "0x%" . $f;
    }

    sub format_refaddr {
        require Scalar::Util;
        sprintf $refaddr_format, Scalar::Util::refaddr(shift);
    }

    1
EOC
}

#
# add-to or query the table of already seen references
#
sub Seen {
  my($s, $g) = @_;
  if (defined($g) &amp;&amp; (ref($g) eq 'HASH'))  {
    init_refaddr_format();
    my($k, $v, $id);
    while (($k, $v) = each %$g) {
      if (defined $v) {
        if (ref $v) {
          $id = format_refaddr($v);
          if ($k =~ /^[*](.*)$/) {
            $k = (ref $v eq 'ARRAY') ? ( "\\\@" . $1 ) :
                 (ref $v eq 'HASH')  ? ( "\\\%" . $1 ) :
                 (ref $v eq 'CODE')  ? ( "\\\&amp;" . $1 ) :
                 (   "\$" . $1 ) ;
          }
          elsif ($k !~ /^\$/) {
            $k = "\$" . $k;
          }
          $s-&gt;{seen}{$id} = [$k, $v];
        }
        else {
          Carp::carp("Only refs supported, ignoring non-ref item \$$k");
        }
      }
      else {
        Carp::carp("Value of ref must be defined; ignoring undefined item \$$k");
      }
    }
    return $s;
  }
  else {
    return map { @$_ } values %{$s-&gt;{seen}};
  }
}

#
# set or query the values to be dumped
#
sub Values {
  my($s, $v) = @_;
  if (defined($v)) {
    if (ref($v) eq 'ARRAY')  {
      $s-&gt;{todump} = [@$v];        # make a copy
      return $s;
    }
    else {
      Carp::croak("Argument to Values, if provided, must be array ref");
    }
  }
  else {
    return @{$s-&gt;{todump}};
  }
}

#
# set or query the names of the values to be dumped
#
sub Names {
  my($s, $n) = @_;
  if (defined($n)) {
    if (ref($n) eq 'ARRAY') {
      $s-&gt;{names} = [@$n];         # make a copy
      return $s;
    }
    else {
      Carp::croak("Argument to Names, if provided, must be array ref");
    }
  }
  else {
    return @{$s-&gt;{names}};
  }
}

sub DESTROY {}

sub Dump {
  return &amp;Dumpxs
    unless $Data::Dumper::Useperl || (ref($_[0]) &amp;&amp; $_[0]-&gt;{useperl})
            # Use pure perl version on earlier releases on EBCDIC platforms
        || (! $IS_ASCII &amp;&amp; $] lt 5.021_010);
  return &amp;Dumpperl;
}

#
# dump the refs in the current dumper object.
# expects same args as new() if called via package name.
#
sub Dumpperl {
  my($s) = shift;
  my(@out, $val, $name);
  my($i) = 0;
  local(@post);
  init_refaddr_format();

  $s = $s-&gt;new(@_) unless ref $s;

  for $val (@{$s-&gt;{todump}}) {
    @post = ();
    $name = $s-&gt;{names}[$i++];
    $name = $s-&gt;_refine_name($name, $val, $i);

    my $valstr;
    {
      local($s-&gt;{apad}) = $s-&gt;{apad};
      $s-&gt;{apad} .= ' ' x (length($name) + 3) if $s-&gt;{indent} &gt;= 2 and !$s-&gt;{terse};
      $valstr = $s-&gt;_dump($val, $name);
    }

    $valstr = "$name = " . $valstr . ';' if @post or !$s-&gt;{terse};
    my $out = $s-&gt;_compose_out($valstr, \@post);

    push @out, $out;
  }
  return wantarray ? @out : join('', @out);
}

# wrap string in single quotes (escaping if needed)
sub _quote {
    my $val = shift;
    $val =~ s/([\\\'])/\\$1/g;
    return  "'" . $val .  "'";
}

# Old Perls (5.14-) have trouble resetting vstring magic when it is no
# longer valid.
use constant _bad_vsmg =&gt; defined &amp;_vstring &amp;&amp; (_vstring(~v0)||'') eq "v0";

#
# twist, toil and turn;
# and recurse, of course.
# sometimes sordidly;
# and curse if no recourse.
#
sub _dump {
  my($s, $val, $name) = @_;
  my($out, $type, $id, $sname);

  $type = ref $val;
  $out = "";

  if ($type) {

    # Call the freezer method if it's specified and the object has the
    # method.  Trap errors and warn() instead of die()ing, like the XS
    # implementation.
    my $freezer = $s-&gt;{freezer};
    if ($freezer and UNIVERSAL::can($val, $freezer)) {
      eval { $val-&gt;$freezer() };
      warn "WARNING(Freezer method call failed): $@" if $@;
    }

    require Scalar::Util;
    my $realpack = Scalar::Util::blessed($val);
    my $realtype = $realpack ? Scalar::Util::reftype($val) : ref $val;
    $id = format_refaddr($val);

    # Note: By this point $name is always defined and of non-zero length.
    # Keep a tab on it so that we do not fall into recursive pit.
    if (exists $s-&gt;{seen}{$id}) {
      if ($s-&gt;{purity} and $s-&gt;{level} &gt; 0) {
        $out = ($realtype eq 'HASH')  ? '{}' :
               ($realtype eq 'ARRAY') ? '[]' :
               'do{my $o}' ;
        push @post, $name . " = " . $s-&gt;{seen}{$id}[0];
      }
      else {
        $out = $s-&gt;{seen}{$id}[0];
        if ($name =~ /^([\@\%])/) {
          my $start = $1;
          if ($out =~ /^\\$start/) {
            $out = substr($out, 1);
          }
          else {
            $out = $start . '{' . $out . '}';
          }
        }
      }
      return $out;
    }
    else {
      # store our name
      $s-&gt;{seen}{$id} = [ (
          ($name =~ /^[@%]/)
            ? ('\\' . $name )
            : ($realtype eq 'CODE' and $name =~ /^[*](.*)$/)
              ? ('\\&amp;' . $1 )
              : $name
        ), $val ];
    }
    my $no_bless = 0;
    my $is_regex = 0;
    if ( $realpack and ($] &gt;= 5.009005 ? re::is_regexp($val) : $realpack eq 'Regexp') ) {
        $is_regex = 1;
        $no_bless = $realpack eq 'Regexp';
    }

    # If purity is not set and maxdepth is set, then check depth:
    # if we have reached maximum depth, return the string
    # representation of the thing we are currently examining
    # at this depth (i.e., 'Foo=ARRAY(0xdeadbeef)').
    if (!$s-&gt;{purity}
      and defined($s-&gt;{maxdepth})
      and $s-&gt;{maxdepth} &gt; 0
      and $s-&gt;{level} &gt;= $s-&gt;{maxdepth})
    {
      return qq['$val'];
    }

    # avoid recursing infinitely [perl #122111]
    if ($s-&gt;{maxrecurse} &gt; 0
        and $s-&gt;{level} &gt;= $s-&gt;{maxrecurse}) {
        die "Recursion limit of $s-&gt;{maxrecurse} exceeded";
    }

    # we have a blessed ref
    my ($blesspad);
    if ($realpack and !$no_bless) {
      $out = $s-&gt;{'bless'} . '( ';
      $blesspad = $s-&gt;{apad};
      $s-&gt;{apad} .= '       ' if ($s-&gt;{indent} &gt;= 2);
    }

    $s-&gt;{level}++;
    my $ipad = $s-&gt;{xpad} x $s-&gt;{level};

    if ($is_regex) {
        my $pat;
        my $flags = "";
        if (defined(*re::regexp_pattern{CODE})) {
          ($pat, $flags) = re::regexp_pattern($val);
        }
        else {
          $pat = "$val";
        }
        $pat =~ s &lt;(\\.)|/&gt; { $1 || '\\/' }ge;
        $out .= "qr/$pat/$flags";
    }
    elsif ($realtype eq 'SCALAR' || $realtype eq 'REF'
    || $realtype eq 'VSTRING') {
      if ($realpack) {
        $out .= 'do{\\(my $o = ' . $s-&gt;_dump($$val, "\${$name}") . ')}';
      }
      else {
        $out .= '\\' . $s-&gt;_dump($$val, "\${$name}");
      }
    }
    elsif ($realtype eq 'GLOB') {
      $out .= '\\' . $s-&gt;_dump($$val, "*{$name}");
    }
    elsif ($realtype eq 'ARRAY') {
      my($pad, $mname);
      my($i) = 0;
      $out .= ($name =~ /^\@/) ? '(' : '[';
      $pad = $s-&gt;{sep} . $s-&gt;{pad} . $s-&gt;{apad};
      ($name =~ /^\@(.*)$/) ? ($mname = "\$" . $1) :
    # omit -&gt; if $foo-&gt;[0]-&gt;{bar}, but not ${$foo-&gt;[0]}-&gt;{bar}
        ($name =~ /^\\?[\%\@\*\$][^{].*[]}]$/) ? ($mname = $name) :
        ($mname = $name . '-&gt;');
      $mname .= '-&gt;' if $mname =~ /^\*.+\{[A-Z]+\}$/;
      for my $v (@$val) {
        $sname = $mname . '[' . $i . ']';
        $out .= $pad . $ipad . '#' . $i
          if $s-&gt;{indent} &gt;= 3;
        $out .= $pad . $ipad . $s-&gt;_dump($v, $sname);
        $out .= ","
            if $i++ &lt; $#$val
            || ($s-&gt;{trailingcomma} &amp;&amp; $s-&gt;{indent} &gt;= 1);
      }
      $out .= $pad . ($s-&gt;{xpad} x ($s-&gt;{level} - 1)) if $i;
      $out .= ($name =~ /^\@/) ? ')' : ']';
    }
    elsif ($realtype eq 'HASH') {
      my ($k, $v, $pad, $lpad, $mname, $pair);
      $out .= ($name =~ /^\%/) ? '(' : '{';
      $pad = $s-&gt;{sep} . $s-&gt;{pad} . $s-&gt;{apad};
      $lpad = $s-&gt;{apad};
      $pair = $s-&gt;{pair};
      ($name =~ /^\%(.*)$/) ? ($mname = "\$" . $1) :
    # omit -&gt; if $foo-&gt;[0]-&gt;{bar}, but not ${$foo-&gt;[0]}-&gt;{bar}
        ($name =~ /^\\?[\%\@\*\$][^{].*[]}]$/) ? ($mname = $name) :
        ($mname = $name . '-&gt;');
      $mname .= '-&gt;' if $mname =~ /^\*.+\{[A-Z]+\}$/;
      my $sortkeys = defined($s-&gt;{sortkeys}) ? $s-&gt;{sortkeys} : '';
      my $keys = [];
      if ($sortkeys) {
        if (ref($s-&gt;{sortkeys}) eq 'CODE') {
          $keys = $s-&gt;{sortkeys}($val);
          unless (ref($keys) eq 'ARRAY') {
            Carp::carp("Sortkeys subroutine did not return ARRAYREF");
            $keys = [];
          }
        }
        else {
          $keys = [ sort keys %$val ];
        }
      }

      # Ensure hash iterator is reset
      keys(%$val);

      my $key;
      while (($k, $v) = ! $sortkeys ? (each %$val) :
         @$keys ? ($key = shift(@$keys), $val-&gt;{$key}) :
         () )
      {
        my $nk = $s-&gt;_dump($k, "");

        # _dump doesn't quote numbers of this form
        if ($s-&gt;{quotekeys} &amp;&amp; $nk =~ /^(?:0|-?[1-9][0-9]{0,8})\z/) {
          $nk = $s-&gt;{useqq} ? qq("$nk") : qq('$nk');
        }
        elsif (!$s-&gt;{quotekeys} and $nk =~ /^[\"\']([A-Za-z_]\w*)[\"\']$/) {
          $nk = $1
        }

        $sname = $mname . '{' . $nk . '}';
        $out .= $pad . $ipad . $nk . $pair;

        # temporarily alter apad
        $s-&gt;{apad} .= (" " x (length($nk) + 4))
          if $s-&gt;{indent} &gt;= 2;
        $out .= $s-&gt;_dump($val-&gt;{$k}, $sname) . ",";
        $s-&gt;{apad} = $lpad
          if $s-&gt;{indent} &gt;= 2;
      }
      if (substr($out, -1) eq ',') {
        chop $out if !$s-&gt;{trailingcomma} || !$s-&gt;{indent};
        $out .= $pad . ($s-&gt;{xpad} x ($s-&gt;{level} - 1));
      }
      $out .= ($name =~ /^\%/) ? ')' : '}';
    }
    elsif ($realtype eq 'CODE') {
      if ($s-&gt;{deparse}) {
        require B::Deparse;
        my $sub =  'sub ' . (B::Deparse-&gt;new)-&gt;coderef2text($val);
        $pad    =  $s-&gt;{sep} . $s-&gt;{pad} . $s-&gt;{apad} . $s-&gt;{xpad} x ($s-&gt;{level} - 1);
        $sub    =~ s/\n/$pad/gs;
        $out   .=  $sub;
      }
      else {
        $out .= 'sub { "DUMMY" }';
        Carp::carp("Encountered CODE ref, using dummy placeholder") if $s-&gt;{purity};
      }
    }
    else {
      Carp::croak("Can't handle '$realtype' type");
    }

    if ($realpack and !$no_bless) { # we have a blessed ref
      $out .= ', ' . _quote($realpack) . ' )';
      $out .= '-&gt;' . $s-&gt;{toaster} . '()'
        if $s-&gt;{toaster} ne '';
      $s-&gt;{apad} = $blesspad;
    }
    $s-&gt;{level}--;
  }
  else {                                 # simple scalar

    my $ref = \$_[1];
    my $v;
    # first, catalog the scalar
    if ($name ne '') {
      $id = format_refaddr($ref);
      if (exists $s-&gt;{seen}{$id}) {
        if ($s-&gt;{seen}{$id}[2]) {
          $out = $s-&gt;{seen}{$id}[0];
          #warn "[&lt;$out]\n";
          return "\${$out}";
        }
      }
      else {
        #warn "[&gt;\\$name]\n";
        $s-&gt;{seen}{$id} = ["\\$name", $ref];
      }
    }
    $ref = \$val;
    if (ref($ref) eq 'GLOB') {  # glob
      my $name = substr($val, 1);
      $name =~ s/^main::(?!\z)/::/;
      if ($name =~ /\A(?:[A-Z_a-z][0-9A-Z_a-z]*)?::(?:[0-9A-Z_a-z]+::)*[0-9A-Z_a-z]*\z/ &amp;&amp; $name ne 'main::') {
        $sname = $name;
      }
      else {
        local $s-&gt;{useqq} = IS_PRE_516_PERL &amp;&amp; ($s-&gt;{useqq} || $name =~ /[^\x00-\x7f]/) ? 1 : $s-&gt;{useqq};
        $sname = $s-&gt;_dump(
          $name eq 'main::' || $] &lt; 5.007 &amp;&amp; $name eq "main::\0"
            ? ''
            : $name,
          "",
        );
        $sname = '{' . $sname . '}';
      }
      if ($s-&gt;{purity}) {
        my $k;
        local ($s-&gt;{level}) = 0;
        for $k (qw(SCALAR ARRAY HASH)) {
          my $gval = *$val{$k};
          next unless defined $gval;
          next if $k eq "SCALAR" &amp;&amp; ! defined $$gval;  # always there

          # _dump can push into @post, so we hold our place using $postlen
          my $postlen = scalar @post;
          $post[$postlen] = "\*$sname = ";
          local ($s-&gt;{apad}) = " " x length($post[$postlen]) if $s-&gt;{indent} &gt;= 2;
          $post[$postlen] .= $s-&gt;_dump($gval, "\*$sname\{$k\}");
        }
      }
      $out .= '*' . $sname;
    }
    elsif (!defined($val)) {
      $out .= "undef";
    }
    elsif (defined &amp;_vstring and $v = _vstring($val)
      and !_bad_vsmg || eval $v eq $val) {
      $out .= $v;
    }
    elsif (!defined &amp;_vstring
       and ref $ref eq 'VSTRING' || eval{Scalar::Util::isvstring($val)}) {
      $out .= sprintf "%vd", $val;
    }
    # \d here would treat "1\x{660}" as a safe decimal number
    elsif ($val =~ /^(?:0|-?[1-9][0-9]{0,8})\z/) { # safe decimal number
      $out .= $val;
    }
    else {                 # string
      if ($s-&gt;{useqq} or $val =~ tr/\0-\377//c) {
        # Fall back to qq if there's Unicode
        $out .= qquote($val, $s-&gt;{useqq});
      }
      else {
        $out .= _quote($val);
      }
    }
  }
  if ($id) {
    # if we made it this far, $id was added to seen list at current
    # level, so remove it to get deep copies
    if ($s-&gt;{deepcopy}) {
      delete($s-&gt;{seen}{$id});
    }
    elsif ($name) {
      $s-&gt;{seen}{$id}[2] = 1;
    }
  }
  return $out;
}

#
# non-OO style of earlier version
#
sub Dumper {
  return Data::Dumper-&gt;Dump([@_]);
}

# compat stub
sub DumperX {
  return Data::Dumper-&gt;Dumpxs([@_], []);
}

#
# reset the "seen" cache
#
sub Reset {
  my($s) = shift;
  $s-&gt;{seen} = {};
  return $s;
}

sub Indent {
  my($s, $v) = @_;
  if (@_ &gt;= 2) {
    if ($v == 0) {
      $s-&gt;{xpad} = "";
      $s-&gt;{sep} = "";
    }
    else {
      $s-&gt;{xpad} = "  ";
      $s-&gt;{sep} = "\n";
    }
    $s-&gt;{indent} = $v;
    return $s;
  }
  else {
    return $s-&gt;{indent};
  }
}

sub Trailingcomma {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{trailingcomma} = $v), return $s) : $s-&gt;{trailingcomma};
}

sub Pair {
    my($s, $v) = @_;
    @_ &gt;= 2 ? (($s-&gt;{pair} = $v), return $s) : $s-&gt;{pair};
}

sub Pad {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{pad} = $v), return $s) : $s-&gt;{pad};
}

sub Varname {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{varname} = $v), return $s) : $s-&gt;{varname};
}

sub Purity {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{purity} = $v), return $s) : $s-&gt;{purity};
}

sub Useqq {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{useqq} = $v), return $s) : $s-&gt;{useqq};
}

sub Terse {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{terse} = $v), return $s) : $s-&gt;{terse};
}

sub Freezer {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{freezer} = $v), return $s) : $s-&gt;{freezer};
}

sub Toaster {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{toaster} = $v), return $s) : $s-&gt;{toaster};
}

sub Deepcopy {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{deepcopy} = $v), return $s) : $s-&gt;{deepcopy};
}

sub Quotekeys {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{quotekeys} = $v), return $s) : $s-&gt;{quotekeys};
}

sub Bless {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{'bless'} = $v), return $s) : $s-&gt;{'bless'};
}

sub Maxdepth {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{'maxdepth'} = $v), return $s) : $s-&gt;{'maxdepth'};
}

sub Maxrecurse {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{'maxrecurse'} = $v), return $s) : $s-&gt;{'maxrecurse'};
}

sub Useperl {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{'useperl'} = $v), return $s) : $s-&gt;{'useperl'};
}

sub Sortkeys {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{'sortkeys'} = $v), return $s) : $s-&gt;{'sortkeys'};
}

sub Deparse {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{'deparse'} = $v), return $s) : $s-&gt;{'deparse'};
}

sub Sparseseen {
  my($s, $v) = @_;
  @_ &gt;= 2 ? (($s-&gt;{'noseen'} = $v), return $s) : $s-&gt;{'noseen'};
}

# used by qquote below
my %esc = (
    "\a" =&gt; "\\a",
    "\b" =&gt; "\\b",
    "\t" =&gt; "\\t",
    "\n" =&gt; "\\n",
    "\f" =&gt; "\\f",
    "\r" =&gt; "\\r",
    "\e" =&gt; "\\e",
);

my $low_controls = ($IS_ASCII)

                   # This includes \177, because traditionally it has been
                   # output as octal, even though it isn't really a "low"
                   # control
                   ? qr/[\0-\x1f\177]/

                     # EBCDIC low controls.
                   : qr/[\0-\x3f]/;

# put a string value in double quotes
sub qquote {
  local($_) = shift;
  s/([\\\"\@\$])/\\$1/g;

  # This efficiently changes the high ordinal characters to \x{} if the utf8
  # flag is on.  On ASCII platforms, the high ordinals are all the
  # non-ASCII's.  On EBCDIC platforms, we don't include in these the non-ASCII
  # controls whose ordinals are less than SPACE, excluded below by the range
  # \0-\x3f.  On ASCII platforms this range just compiles as part of :ascii:.
  # On EBCDIC platforms, there is just one outlier high ordinal control, and
  # it gets output as \x{}.
  my $bytes; { use bytes; $bytes = length }
  s/([^[:ascii:]\0-\x3f])/sprintf("\\x{%x}",ord($1))/ge
    if $bytes &gt; length

       # The above doesn't get the EBCDIC outlier high ordinal control when
       # the string is UTF-8 but there are no UTF-8 variant characters in it.
       # We want that to come out as \x{} anyway.  We need is_utf8() to do
       # this.
       || (! $IS_ASCII &amp;&amp; $] ge 5.008_001 &amp;&amp; utf8::is_utf8($_));

  return qq("$_") unless /[[:^print:]]/;  # fast exit if only printables

  # Here, there is at least one non-printable to output.  First, translate the
  # escapes.
  s/([\a\b\t\n\f\r\e])/$esc{$1}/g;

  # no need for 3 digits in escape for octals not followed by a digit.
  s/($low_controls)(?!\d)/'\\'.sprintf('%o',ord($1))/eg;

  # But otherwise use 3 digits
  s/($low_controls)/'\\'.sprintf('%03o',ord($1))/eg;

    # all but last branch below not supported --BEHAVIOR SUBJECT TO CHANGE--
  my $high = shift || "";
    if ($high eq "iso8859") {   # Doesn't escape the Latin1 printables
      if ($IS_ASCII) {
        s/([\200-\240])/'\\'.sprintf('%o',ord($1))/eg;
      }
      elsif ($] ge 5.007_003) {
        my $high_control = utf8::unicode_to_native(0x9F);
        s/$high_control/sprintf('\\%o',ord($1))/eg;
      }
    } elsif ($high eq "utf8") {
#     Some discussion of what to do here is in
#       https://rt.perl.org/Ticket/Display.html?id=113088
#     use utf8;
#     $str =~ s/([^\040-\176])/sprintf "\\x{%04x}", ord($1)/ge;
    } elsif ($high eq "8bit") {
        # leave it as it is
    } else {
      s/([[:^ascii:]])/'\\'.sprintf('%03o',ord($1))/eg;
      #s/([^\040-\176])/sprintf "\\x{%04x}", ord($1)/ge;
    }

  return qq("$_");
}

# helper sub to sort hash keys in Perl &lt; 5.8.0 where we don't have
# access to sortsv() from XS
sub _sortkeys { [ sort keys %{$_[0]} ] }

sub _refine_name {
    my $s = shift;
    my ($name, $val, $i) = @_;
    if (defined $name) {
      if ($name =~ /^[*](.*)$/) {
        if (defined $val) {
            $name = (ref $val eq 'ARRAY') ? ( "\@" . $1 ) :
              (ref $val eq 'HASH')  ? ( "\%" . $1 ) :
              (ref $val eq 'CODE')  ? ( "\*" . $1 ) :
              ( "\$" . $1 ) ;
        }
        else {
          $name = "\$" . $1;
        }
      }
      elsif ($name !~ /^\$/) {
        $name = "\$" . $name;
      }
    }
    else { # no names provided
      $name = "\$" . $s-&gt;{varname} . $i;
    }
    return $name;
}

sub _compose_out {
    my $s = shift;
    my ($valstr, $postref) = @_;
    my $out = "";
    $out .= $s-&gt;{pad} . $valstr . $s-&gt;{sep};
    if (@{$postref}) {
        $out .= $s-&gt;{pad} .
            join(';' . $s-&gt;{sep} . $s-&gt;{pad}, @{$postref}) .
            ';' .
            $s-&gt;{sep};
    }
    return $out;
}

1;
__END__

=head1 NAME

Data::Dumper - stringified perl data structures, suitable for both printing and C&lt;eval&gt;

=head1 SYNOPSIS

    use Data::Dumper;

    # simple procedural interface
    print Dumper($foo, $bar);

    # extended usage with names
    print Data::Dumper-&gt;Dump([$foo, $bar], [qw(foo *ary)]);

    # configuration variables
    {
      local $Data::Dumper::Purity = 1;
      eval Data::Dumper-&gt;Dump([$foo, $bar], [qw(foo *ary)]);
    }

    # OO usage
    $d = Data::Dumper-&gt;new([$foo, $bar], [qw(foo *ary)]);
       ...
    print $d-&gt;Dump;
       ...
    $d-&gt;Purity(1)-&gt;Terse(1)-&gt;Deepcopy(1);
    eval $d-&gt;Dump;


=head1 DESCRIPTION

Given a list of scalars or reference variables, writes out their contents in
perl syntax. The references can also be objects.  The content of each
variable is output in a single Perl statement.  Handles self-referential
structures correctly.

The return value can be C&lt;eval&gt;ed to get back an identical copy of the
original reference structure.  (Please do consider the security implications
of eval'ing code from untrusted sources!)

Any references that are the same as one of those passed in will be named
C&lt;$VAR&gt;I&lt;n&gt; (where I&lt;n&gt; is a numeric suffix), and other duplicate references
to substructures within C&lt;$VAR&gt;I&lt;n&gt; will be appropriately labeled using arrow
notation.  You can specify names for individual values to be dumped if you
use the C&lt;Dump()&gt; method, or you can change the default C&lt;$VAR&gt; prefix to
something else.  See C&lt;$Data::Dumper::Varname&gt; and C&lt;$Data::Dumper::Terse&gt;
below.

The default output of self-referential structures can be C&lt;eval&gt;ed, but the
nested references to C&lt;$VAR&gt;I&lt;n&gt; will be undefined, since a recursive
structure cannot be constructed using one Perl statement.  You should set the
C&lt;Purity&gt; flag to 1 to get additional statements that will correctly fill in
these references.  Moreover, if C&lt;eval&gt;ed when strictures are in effect,
you need to ensure that any variables it accesses are previously declared.

In the extended usage form, the references to be dumped can be given
user-specified names.  If a name begins with a C&lt;*&gt;, the output will
describe the dereferenced type of the supplied reference for hashes and
arrays, and coderefs.  Output of names will be avoided where possible if
the C&lt;Terse&gt; flag is set.

In many cases, methods that are used to set the internal state of the
object will return the object itself, so method calls can be conveniently
chained together.

Several styles of output are possible, all controlled by setting
the C&lt;Indent&gt; flag.  See L&lt;Configuration Variables or Methods&gt; below
for details.


=head2 Methods

=over 4

=item I&lt;PACKAGE&gt;-&gt;new(I&lt;ARRAYREF [&gt;, I&lt;ARRAYREF]&gt;)

Returns a newly created C&lt;Data::Dumper&gt; 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 need not have a leading
C&lt;$&gt; sign, and must be comprised of alphanumeric characters.  You can begin
a name with a C&lt;*&gt; to specify that the dereferenced type must be dumped
instead of the reference itself, for ARRAY and HASH references.

The prefix specified by C&lt;$Data::Dumper::Varname&gt; will be used with a
numeric suffix if the name for a value is undefined.

Data::Dumper will catalog all references encountered while dumping the
values. Cross-references (in the form of names of substructures in perl
syntax) will be inserted at all possible points, preserving any structural
interdependencies in the original set of values.  Structure traversal is
depth-first,  and proceeds in order from the first supplied value to
the last.

=item I&lt;$OBJ&gt;-&gt;Dump  I&lt;or&gt;  I&lt;PACKAGE&gt;-&gt;Dump(I&lt;ARRAYREF [&gt;, I&lt;ARRAYREF]&gt;)

Returns the stringified form of the values stored in the object (preserving
the order in which they were supplied to C&lt;new&gt;), subject to the
configuration options below.  In a list context, it returns a list
of strings corresponding to the supplied values.

The second form, for convenience, simply calls the C&lt;new&gt; method on its
arguments before dumping the object immediately.

=item I&lt;$OBJ&gt;-&gt;Seen(I&lt;[HASHREF]&gt;)

Queries or adds to the internal table of already encountered references.
You must use C&lt;Reset&gt; to explicitly clear the table if needed.  Such
references are not dumped; instead, their names are inserted wherever they
are encountered subsequently.  This is useful especially for properly
dumping subroutine references.

Expects an anonymous hash of name =&gt; value pairs.  Same rules apply for names
as in C&lt;new&gt;.  If no argument is supplied, will return the "seen" list of
name =&gt; value pairs, in a list context.  Otherwise, returns the object
itself.

=item I&lt;$OBJ&gt;-&gt;Values(I&lt;[ARRAYREF]&gt;)

Queries or replaces the internal array of values that will be dumped.  When
called without arguments, returns the values as a list.  When called with a
reference to an array of replacement values, returns the object itself.  When
called with any other type of argument, dies.

=item I&lt;$OBJ&gt;-&gt;Names(I&lt;[ARRAYREF]&gt;)

Queries or replaces the internal array of user supplied names for the values
that will be dumped.  When called without arguments, returns the names.  When
called with an array of replacement names, returns the object itself.  If the
number of replacement names exceeds the number of values to be named, the
excess names will not be used.  If the number of replacement names falls short
of the number of values to be named, the list of replacement names will be
exhausted and remaining values will not be renamed.  When
called with any other type of argument, dies.

=item I&lt;$OBJ&gt;-&gt;Reset

Clears the internal table of "seen" references and returns the object
itself.

=back

=head2 Functions

=over 4

=item Dumper(I&lt;LIST&gt;)

Returns the stringified form of the values in the list, subject to the
configuration options below.  The values will be named C&lt;$VAR&gt;I&lt;n&gt; in the
output, where I&lt;n&gt; is a numeric suffix.  Will return a list of strings
in a list context.

=back

=head2 Configuration Variables or Methods

Several configuration variables can be used to control the kind of output
generated when using the procedural interface.  These variables are usually
C&lt;local&gt;ized in a block so that other parts of the code are not affected by
the change.

These variables determine the default state of the object created by calling
the C&lt;new&gt; method, but cannot be used to alter the state of the object
thereafter.  The equivalent method names should be used instead to query
or set the internal state of the object.

The method forms return the object itself when called with arguments,
so that they can be chained together nicely.

=over 4

=item *

$Data::Dumper::Indent  I&lt;or&gt;  I&lt;$OBJ&gt;-&gt;Indent(I&lt;[NEWVAL]&gt;)

Controls the style of indentation.  It can be set to 0, 1, 2 or 3.  Style 0
spews output without any newlines, indentation, or spaces between list
items.  It is the most compact format possible that can still be called
valid perl.  Style 1 outputs a readable form with newlines but no fancy
indentation (each level in the structure is simply indented by a fixed
amount of whitespace).  Style 2 (the default) outputs a very readable form
which takes into account the length of hash keys (so the hash value lines
up).  Style 3 is like style 2, but also annotates the elements of arrays
with their index (but the comment is on its own line, so array output
consumes twice the number of lines).  Style 2 is the default.

=item *

$Data::Dumper::Trailingcomma  I&lt;or&gt;  I&lt;$OBJ&gt;-&gt;Trailingcomma(I&lt;[NEWVAL]&gt;)

Controls whether a comma is added after the last element of an array or
hash. Even when true, no comma is added between the last element of an array
or hash and a closing bracket when they appear on the same line. The default
is false.

=item *

$Data::Dumper::Purity  I&lt;or&gt;  I&lt;$OBJ&gt;-&gt;Purity(I&lt;[NEWVAL]&gt;)

Controls the degree to which the output can be C&lt;eval&gt;ed to recreate the
supplied reference structures.  Setting it to 1 will output additional perl
statements that will correctly recreate nested references.  The default is
0.

=item *

$Data::Dumper::Pad  I&lt;or&gt;  I&lt;$OBJ&gt;-&gt;Pad(I&lt;[NEWVAL]&gt;)

Specifies the string that will be prefixed to every line of the output.
Empty string by default.

=item *

$Data::Dumper::Varname  I&lt;or&gt;  I&lt;$OBJ&gt;-&gt;Varname(I&lt;[NEWVAL]&gt;)

Contains the prefix to use for tagging variable names in the output. The
default is "VAR".

=item *

$Data::Dumper::Useqq  I&lt;or&gt;  I&lt;$OBJ&gt;-&gt;Useqq(I&lt;[NEWVAL]&gt;)

When set, enables the use of double quotes for representing string values.
Whitespace other than space will be represented as C&lt;[\n\t\r]&gt;, "unsafe"
characters will be backslashed, and unprintable characters will be output as
quoted octal integers.  The default is 0.

=item *

$Data::Dumper::Terse  I&lt;or&gt;  I&lt;$OBJ&gt;-&gt;Terse(I&lt;[NEWVAL]&gt;)

When set, Data::Dumper will emit single, non-self-referential values as
atoms/terms rather than statements.  This means that the C&lt;$VAR&gt;I&lt;n&gt; names
will be avoided where possible, but be advised that such output may not
always be parseable by C&lt;eval&gt;.

=item *

$Data::Dumper::Freezer  I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Freezer(I&lt;[NEWVAL]&gt;)

Can be set to a method name, or to an empty string to disable the feature.
Data::Dumper will invoke that method via the object before attempting to
stringify it.  This method can alter the contents of the object (if, for
instance, it contains data allocated from C), and even rebless it in a
different package.  The client is responsible for making sure the specified
method can be called via the object, and that the object ends up containing
only perl data types after the method has been called.  Defaults to an empty
string.

If an object does not support the method specified (determined using
UNIVERSAL::can()) then the call will be skipped.  If the method dies a
warning will be generated.

=item *

$Data::Dumper::Toaster  I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Toaster(I&lt;[NEWVAL]&gt;)

Can be set to a method name, or to an empty string to disable the feature.
Data::Dumper will emit a method call for any objects that are to be dumped
using the syntax C&lt;bless(DATA, CLASS)-E&lt;gt&gt;METHOD()&gt;.  Note that this means that
the method specified will have to perform any modifications required on the
object (like creating new state within it, and/or reblessing it in a
different package) and then return it.  The client is responsible for making
sure the method can be called via the object, and that it returns a valid
object.  Defaults to an empty string.

=item *

$Data::Dumper::Deepcopy  I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Deepcopy(I&lt;[NEWVAL]&gt;)

Can be set to a boolean value to enable deep copies of structures.
Cross-referencing will then only be done when absolutely essential
(i.e., to break reference cycles).  Default is 0.

=item *

$Data::Dumper::Quotekeys  I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Quotekeys(I&lt;[NEWVAL]&gt;)

Can be set to a boolean value to control whether hash keys are quoted.
A defined false value will avoid quoting hash keys when it looks like a simple
string.  Default is 1, which will always enclose hash keys in quotes.

=item *

$Data::Dumper::Bless  I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Bless(I&lt;[NEWVAL]&gt;)

Can be set to a string that specifies an alternative to the C&lt;bless&gt;
builtin operator used to create objects.  A function with the specified
name should exist, and should accept the same arguments as the builtin.
Default is C&lt;bless&gt;.

=item *

$Data::Dumper::Pair  I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Pair(I&lt;[NEWVAL]&gt;)

Can be set to a string that specifies the separator between hash keys
and values. To dump nested hash, array and scalar values to JavaScript,
use: C&lt;$Data::Dumper::Pair = ' : ';&gt;. Implementing C&lt;bless&gt; in JavaScript
is left as an exercise for the reader.
A function with the specified name exists, and accepts the same arguments
as the builtin.

Default is: C&lt; =E&lt;gt&gt; &gt;.

=item *

$Data::Dumper::Maxdepth  I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Maxdepth(I&lt;[NEWVAL]&gt;)

Can be set to a positive integer that specifies the depth beyond which
we don't venture into a structure.  Has no effect when
C&lt;Data::Dumper::Purity&gt; is set.  (Useful in debugger when we often don't
want to see more than enough).  Default is 0, which means there is
no maximum depth.

=item *

$Data::Dumper::Maxrecurse  I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Maxrecurse(I&lt;[NEWVAL]&gt;)

Can be set to a positive integer that specifies the depth beyond which
recursion into a structure will throw an exception.  This is intended
as a security measure to prevent perl running out of stack space when
dumping an excessively deep structure.  Can be set to 0 to remove the
limit.  Default is 1000.

=item *

$Data::Dumper::Useperl  I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Useperl(I&lt;[NEWVAL]&gt;)

Can be set to a boolean value which controls whether the pure Perl
implementation of C&lt;Data::Dumper&gt; is used. The C&lt;Data::Dumper&gt; module is
a dual implementation, with almost all functionality written in both
pure Perl and also in XS ('C'). Since the XS version is much faster, it
will always be used if possible. This option lets you override the
default behavior, usually for testing purposes only. Default is 0, which
means the XS implementation will be used if possible.

=item *

$Data::Dumper::Sortkeys  I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Sortkeys(I&lt;[NEWVAL]&gt;)

Can be set to a boolean value to control whether hash keys are dumped in
sorted order. A true value will cause the keys of all hashes to be
dumped in Perl's default sort order. Can also be set to a subroutine
reference which will be called for each hash that is dumped. In this
case C&lt;Data::Dumper&gt; will call the subroutine once for each hash,
passing it the reference of the hash. The purpose of the subroutine is
to return a reference to an array of the keys that will be dumped, in
the order that they should be dumped. Using this feature, you can
control both the order of the keys, and which keys are actually used. In
other words, this subroutine acts as a filter by which you can exclude
certain keys from being dumped. Default is 0, which means that hash keys
are not sorted.

=item *

$Data::Dumper::Deparse  I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Deparse(I&lt;[NEWVAL]&gt;)

Can be set to a boolean value to control whether code references are
turned into perl source code. If set to a true value, C&lt;B::Deparse&gt;
will be used to get the source of the code reference. In older versions,
using this option imposed a significant performance penalty when dumping
parts of a data structure other than code references, but that is no
longer the case.

Caution : use this option only if you know that your coderefs will be
properly reconstructed by C&lt;B::Deparse&gt;.

=item *

$Data::Dumper::Sparseseen I&lt;or&gt;  $I&lt;OBJ&gt;-&gt;Sparseseen(I&lt;[NEWVAL]&gt;)

By default, Data::Dumper builds up the "seen" hash of scalars that
it has encountered during serialization. This is very expensive.
This seen hash is necessary to support and even just detect circular
references. It is exposed to the user via the C&lt;Seen()&gt; call both
for writing and reading.

If you, as a user, do not need explicit access to the "seen" hash,
then you can set the C&lt;Sparseseen&gt; option to allow Data::Dumper
to eschew building the "seen" hash for scalars that are known not
to possess more than one reference. This speeds up serialization
considerably if you use the XS implementation.

Note: If you turn on C&lt;Sparseseen&gt;, then you must not rely on the
content of the seen hash since its contents will be an
implementation detail!

=back

=head2 Exports

=over 4

=item Dumper

=back

=head1 EXAMPLES

Run these code snippets to get a quick feel for the behavior of this
module.  When you are through with these examples, you may want to
add or change the various configuration variables described above,
to see their behavior.  (See the testsuite in the Data::Dumper
distribution for more examples.)


    use Data::Dumper;

    package Foo;
    sub new {bless {'a' =&gt; 1, 'b' =&gt; sub { return "foo" }}, $_[0]};

    package Fuz;                       # a weird REF-REF-SCALAR object
    sub new {bless \($_ = \ 'fu\'z'), $_[0]};

    package main;
    $foo = Foo-&gt;new;
    $fuz = Fuz-&gt;new;
    $boo = [ 1, [], "abcd", \*foo,
             {1 =&gt; 'a', 023 =&gt; 'b', 0x45 =&gt; 'c'},
             \\"p\q\'r", $foo, $fuz];

    ########
    # simple usage
    ########

    $bar = eval(Dumper($boo));
    print($@) if $@;
    print Dumper($boo), Dumper($bar);  # pretty print (no array indices)

    $Data::Dumper::Terse = 1;        # don't output names where feasible
    $Data::Dumper::Indent = 0;       # turn off all pretty print
    print Dumper($boo), "\n";

    $Data::Dumper::Indent = 1;       # mild pretty print
    print Dumper($boo);

    $Data::Dumper::Indent = 3;       # pretty print with array indices
    print Dumper($boo);

    $Data::Dumper::Useqq = 1;        # print strings in double quotes
    print Dumper($boo);

    $Data::Dumper::Pair = " : ";     # specify hash key/value separator
    print Dumper($boo);


    ########
    # recursive structures
    ########

    @c = ('c');
    $c = \@c;
    $b = {};
    $a = [1, $b, $c];
    $b-&gt;{a} = $a;
    $b-&gt;{b} = $a-&gt;[1];
    $b-&gt;{c} = $a-&gt;[2];
    print Data::Dumper-&gt;Dump([$a,$b,$c], [qw(a b c)]);


    $Data::Dumper::Purity = 1;         # fill in the holes for eval
    print Data::Dumper-&gt;Dump([$a, $b], [qw(*a b)]); # print as @a
    print Data::Dumper-&gt;Dump([$b, $a], [qw(*b a)]); # print as %b


    $Data::Dumper::Deepcopy = 1;       # avoid cross-refs
    print Data::Dumper-&gt;Dump([$b, $a], [qw(*b a)]);


    $Data::Dumper::Purity = 0;         # avoid cross-refs
    print Data::Dumper-&gt;Dump([$b, $a], [qw(*b a)]);

    ########
    # deep structures
    ########

    $a = "pearl";
    $b = [ $a ];
    $c = { 'b' =&gt; $b };
    $d = [ $c ];
    $e = { 'd' =&gt; $d };
    $f = { 'e' =&gt; $e };
    print Data::Dumper-&gt;Dump([$f], [qw(f)]);

    $Data::Dumper::Maxdepth = 3;       # no deeper than 3 refs down
    print Data::Dumper-&gt;Dump([$f], [qw(f)]);


    ########
    # object-oriented usage
    ########

    $d = Data::Dumper-&gt;new([$a,$b], [qw(a b)]);
    $d-&gt;Seen({'*c' =&gt; $c});            # stash a ref without printing it
    $d-&gt;Indent(3);
    print $d-&gt;Dump;
    $d-&gt;Reset-&gt;Purity(0);              # empty the seen cache
    print join "----\n", $d-&gt;Dump;


    ########
    # persistence
    ########

    package Foo;
    sub new { bless { state =&gt; 'awake' }, shift }
    sub Freeze {
        my $s = shift;
        print STDERR "preparing to sleep\n";
        $s-&gt;{state} = 'asleep';
        return bless $s, 'Foo::ZZZ';
    }

    package Foo::ZZZ;
    sub Thaw {
        my $s = shift;
        print STDERR "waking up\n";
        $s-&gt;{state} = 'awake';
        return bless $s, 'Foo';
    }

    package main;
    use Data::Dumper;
    $a = Foo-&gt;new;
    $b = Data::Dumper-&gt;new([$a], ['c']);
    $b-&gt;Freezer('Freeze');
    $b-&gt;Toaster('Thaw');
    $c = $b-&gt;Dump;
    print $c;
    $d = eval $c;
    print Data::Dumper-&gt;Dump([$d], ['d']);


    ########
    # symbol substitution (useful for recreating CODE refs)
    ########

    sub foo { print "foo speaking\n" }
    *other = \&amp;foo;
    $bar = [ \&amp;other ];
    $d = Data::Dumper-&gt;new([\&amp;other,$bar],['*other','bar']);
    $d-&gt;Seen({ '*foo' =&gt; \&amp;foo });
    print $d-&gt;Dump;


    ########
    # sorting and filtering hash keys
    ########

    $Data::Dumper::Sortkeys = \&amp;my_filter;
    my $foo = { map { (ord, "$_$_$_") } 'I'..'Q' };
    my $bar = { %$foo };
    my $baz = { reverse %$foo };
    print Dumper [ $foo, $bar, $baz ];

    sub my_filter {
        my ($hash) = @_;
        # return an array ref containing the hash keys to dump
        # in the order that you want them to be dumped
        return [
          # Sort the keys of %$foo in reverse numeric order
            $hash eq $foo ? (sort {$b &lt;=&gt; $a} keys %$hash) :
          # Only dump the odd number keys of %$bar
            $hash eq $bar ? (grep {$_ % 2} keys %$hash) :
          # Sort keys in default order for all other hashes
            (sort keys %$hash)
        ];
    }

=head1 BUGS

Due to limitations of Perl subroutine call semantics, you cannot pass an
array or hash.  Prepend it with a C&lt;\&gt; to pass its reference instead.  This
will be remedied in time, now that Perl has subroutine prototypes.
For now, you need to use the extended usage form, and prepend the
name with a C&lt;*&gt; to output it as a hash or array.

C&lt;Data::Dumper&gt; cheats with CODE references.  If a code reference is
encountered in the structure being processed (and if you haven't set
the C&lt;Deparse&gt; flag), an anonymous subroutine that
contains the string '"DUMMY"' will be inserted in its place, and a warning
will be printed if C&lt;Purity&gt; is set.  You can C&lt;eval&gt; the result, but bear
in mind that the anonymous sub that gets created is just a placeholder.
Even using the C&lt;Deparse&gt; flag will in some cases produce results that
behave differently after being passed to C&lt;eval&gt;; see the documentation
for L&lt;B::Deparse&gt;.

SCALAR objects have the weirdest looking C&lt;bless&gt; workaround.

Pure Perl version of C&lt;Data::Dumper&gt; escapes UTF-8 strings correctly
only in Perl 5.8.0 and later.

=head2 NOTE

Starting from Perl 5.8.1 different runs of Perl will have different
ordering of hash keys.  The change was done for greater security,
see L&lt;perlsec/"Algorithmic Complexity Attacks"&gt;.  This means that
different runs of Perl will have different Data::Dumper outputs if
the data contains hashes.  If you need to have identical Data::Dumper
outputs from different runs of Perl, use the environment variable
PERL_HASH_SEED, see L&lt;perlrun/PERL_HASH_SEED&gt;.  Using this restores
the old (platform-specific) ordering: an even prettier solution might
be to use the C&lt;Sortkeys&gt; filter of Data::Dumper.

=head1 AUTHOR

Gurusamy Sarathy        gsar@activestate.com

Copyright (c) 1996-2019 Gurusamy Sarathy. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 VERSION

Version 2.174

=head1 SEE ALSO

perl(1)

=cut
</pre></body></html>