dumper.html
来自「perl教程」· HTML 代码 · 共 633 行 · 第 1/4 页
HTML
633 行
<dt><strong><a name="item_seen"><em>$OBJ</em>->Seen(<em>[HASHREF]</em>)</a></strong>
<dd>
<p>Queries or adds to the internal table of already encountered references.
You must use <a href="#item_reset"><code>Reset</code></a> 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.</p>
</dd>
<dd>
<p>Expects an anonymous hash of name => value pairs. Same rules apply for names
as in <a href="#item_new"><code>new</code></a>. If no argument is supplied, will return the "seen" list of
name => value pairs, in a list context. Otherwise, returns the object
itself.</p>
</dd>
</li>
<dt><strong><a name="item_values"><em>$OBJ</em>->Values(<em>[ARRAYREF]</em>)</a></strong>
<dd>
<p>Queries or replaces the internal array of values that will be dumped.
When called without arguments, returns the values. Otherwise, returns the
object itself.</p>
</dd>
</li>
<dt><strong><a name="item_names"><em>$OBJ</em>->Names(<em>[ARRAYREF]</em>)</a></strong>
<dd>
<p>Queries or replaces the internal array of user supplied names for the values
that will be dumped. When called without arguments, returns the names.
Otherwise, returns the object itself.</p>
</dd>
</li>
<dt><strong><a name="item_reset"><em>$OBJ</em>->Reset</a></strong>
<dd>
<p>Clears the internal table of "seen" references and returns the object
itself.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="functions">Functions</a></h2>
<dl>
<dt><strong><a name="item_dumper">Dumper(<em>LIST</em>)</a></strong>
<dd>
<p>Returns the stringified form of the values in the list, subject to the
configuration options below. The values will be named <code>$VAR</code><em>n</em> in the
output, where <em>n</em> is a numeric suffix. Will return a list of strings
in a list context.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="configuration_variables_or_methods">Configuration Variables or Methods</a></h2>
<p>Several configuration variables can be used to control the kind of output
generated when using the procedural interface. These variables are usually
<a href="../../lib/Pod/perlfunc.html#item_local"><code>local</code></a>ized in a block so that other parts of the code are not affected by
the change.</p>
<p>These variables determine the default state of the object created by calling
the <a href="#item_new"><code>new</code></a> 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.</p>
<p>The method forms return the object itself when called with arguments,
so that they can be chained together nicely.</p>
<ul>
<li>
<p>$Data::Dumper::Indent <em>or</em> <em>$OBJ</em>->Indent(<em>[NEWVAL]</em>)</p>
<p>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.</p>
</li>
<li>
<p>$Data::Dumper::Purity <em>or</em> <em>$OBJ</em>->Purity(<em>[NEWVAL]</em>)</p>
<p>Controls the degree to which the output can be <a href="../../lib/Pod/perlfunc.html#item_eval"><code>eval</code></a>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.</p>
</li>
<li>
<p>$Data::Dumper::Pad <em>or</em> <em>$OBJ</em>->Pad(<em>[NEWVAL]</em>)</p>
<p>Specifies the string that will be prefixed to every line of the output.
Empty string by default.</p>
</li>
<li>
<p>$Data::Dumper::Varname <em>or</em> <em>$OBJ</em>->Varname(<em>[NEWVAL]</em>)</p>
<p>Contains the prefix to use for tagging variable names in the output. The
default is "VAR".</p>
</li>
<li>
<p>$Data::Dumper::Useqq <em>or</em> <em>$OBJ</em>->Useqq(<em>[NEWVAL]</em>)</p>
<p>When set, enables the use of double quotes for representing string values.
Whitespace other than space will be represented as <code>[\n\t\r]</code>, "unsafe"
characters will be backslashed, and unprintable characters will be output as
quoted octal integers. Since setting this variable imposes a performance
penalty, the default is 0. <a href="#item_dump"><code>Dump()</code></a> will run slower if this flag is set,
since the fast XSUB implementation doesn't support it yet.</p>
</li>
<li>
<p>$Data::Dumper::Terse <em>or</em> <em>$OBJ</em>->Terse(<em>[NEWVAL]</em>)</p>
<p>When set, Data::Dumper will emit single, non-self-referential values as
atoms/terms rather than statements. This means that the <code>$VAR</code><em>n</em> names
will be avoided where possible, but be advised that such output may not
always be parseable by <a href="../../lib/Pod/perlfunc.html#item_eval"><code>eval</code></a>.</p>
</li>
<li>
<p>$Data::Dumper::Freezer <em>or</em> $<em>OBJ</em>->Freezer(<em>[NEWVAL]</em>)</p>
<p>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.</p>
<p>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.</p>
</li>
<li>
<p>$Data::Dumper::Toaster <em>or</em> $<em>OBJ</em>->Toaster(<em>[NEWVAL]</em>)</p>
<p>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 <a href="../../lib/Pod/perlfunc.html#item_bless"><code>bless(DATA, CLASS)->METHOD()</code></a>. 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.</p>
</li>
<li>
<p>$Data::Dumper::Deepcopy <em>or</em> $<em>OBJ</em>->Deepcopy(<em>[NEWVAL]</em>)</p>
<p>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.</p>
</li>
<li>
<p>$Data::Dumper::Quotekeys <em>or</em> $<em>OBJ</em>->Quotekeys(<em>[NEWVAL]</em>)</p>
<p>Can be set to a boolean value to control whether hash keys are quoted.
A 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.</p>
</li>
<li>
<p>$Data::Dumper::Bless <em>or</em> $<em>OBJ</em>->Bless(<em>[NEWVAL]</em>)</p>
<p>Can be set to a string that specifies an alternative to the <a href="../../lib/Pod/perlfunc.html#item_bless"><code>bless</code></a>
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 <a href="../../lib/Pod/perlfunc.html#item_bless"><code>bless</code></a>.</p>
</li>
<li>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?