Install Perl 5.8.8
[msysgit.git] / mingw / html / ext / Data / Dumper / Dumper.html
blobe33d0015eaefb5568226c545321b885ef845f48c
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>Data::Dumper - stringified perl data structures, suitable for both printing and C&lt;eval&gt;</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;Data::Dumper - stringified perl data structures, suitable for both printing and C&lt;eval&gt;</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <ul>
27 <li><a href="#methods">Methods</a></li>
28 <li><a href="#functions">Functions</a></li>
29 <li><a href="#configuration_variables_or_methods">Configuration Variables or Methods</a></li>
30 <li><a href="#exports">Exports</a></li>
31 </ul>
33 <li><a href="#examples">EXAMPLES</a></li>
34 <li><a href="#bugs">BUGS</a></li>
35 <ul>
37 <li><a href="#note">NOTE</a></li>
38 </ul>
40 <li><a href="#author">AUTHOR</a></li>
41 <li><a href="#version">VERSION</a></li>
42 <li><a href="#see_also">SEE ALSO</a></li>
43 </ul>
44 <!-- INDEX END -->
46 <hr />
47 <p>
48 </p>
49 <h1><a name="name">NAME</a></h1>
50 <p>Data::Dumper - stringified perl data structures, suitable for both printing and <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a></p>
51 <p>
52 </p>
53 <hr />
54 <h1><a name="synopsis">SYNOPSIS</a></h1>
55 <pre>
56 use Data::Dumper;</pre>
57 <pre>
58 # simple procedural interface
59 print Dumper($foo, $bar);</pre>
60 <pre>
61 # extended usage with names
62 print Data::Dumper-&gt;Dump([$foo, $bar], [qw(foo *ary)]);</pre>
63 <pre>
64 # configuration variables
66 local $Data::Dumper::Purity = 1;
67 eval Data::Dumper-&gt;Dump([$foo, $bar], [qw(foo *ary)]);
68 }</pre>
69 <pre>
70 # OO usage
71 $d = Data::Dumper-&gt;new([$foo, $bar], [qw(foo *ary)]);
72 ...
73 print $d-&gt;Dump;
74 ...
75 $d-&gt;Purity(1)-&gt;Terse(1)-&gt;Deepcopy(1);
76 eval $d-&gt;Dump;</pre>
77 <p>
78 </p>
79 <hr />
80 <h1><a name="description">DESCRIPTION</a></h1>
81 <p>Given a list of scalars or reference variables, writes out their contents in
82 perl syntax. The references can also be objects. The contents of each
83 variable is output in a single Perl statement. Handles self-referential
84 structures correctly.</p>
85 <p>The return value can be <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>ed to get back an identical copy of the
86 original reference structure.</p>
87 <p>Any references that are the same as one of those passed in will be named
88 <code>$VAR</code><em>n</em> (where <em>n</em> is a numeric suffix), and other duplicate references
89 to substructures within <code>$VAR</code><em>n</em> will be appropriately labeled using arrow
90 notation. You can specify names for individual values to be dumped if you
91 use the <a href="#item_dump"><code>Dump()</code></a> method, or you can change the default <code>$VAR</code> prefix to
92 something else. See <code>$Data::Dumper::Varname</code> and <code>$Data::Dumper::Terse</code>
93 below.</p>
94 <p>The default output of self-referential structures can be <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>ed, but the
95 nested references to <code>$VAR</code><em>n</em> will be undefined, since a recursive
96 structure cannot be constructed using one Perl statement. You should set the
97 <code>Purity</code> flag to 1 to get additional statements that will correctly fill in
98 these references. Moreover, if <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>ed when strictures are in effect,
99 you need to ensure that any variables it accesses are previously declared.</p>
100 <p>In the extended usage form, the references to be dumped can be given
101 user-specified names. If a name begins with a <code>*</code>, the output will
102 describe the dereferenced type of the supplied reference for hashes and
103 arrays, and coderefs. Output of names will be avoided where possible if
104 the <code>Terse</code> flag is set.</p>
105 <p>In many cases, methods that are used to set the internal state of the
106 object will return the object itself, so method calls can be conveniently
107 chained together.</p>
108 <p>Several styles of output are possible, all controlled by setting
109 the <code>Indent</code> flag. See <a href="#configuration_variables_or_methods">Configuration Variables or Methods</a> below
110 for details.</p>
112 </p>
113 <h2><a name="methods">Methods</a></h2>
114 <dl>
115 <dt><strong><a name="item_new"><em>PACKAGE</em>-&gt;new(<em>ARRAYREF [</em>, <em>ARRAYREF]</em>)</a></strong>
117 <dd>
118 <p>Returns a newly created <code>Data::Dumper</code> object. The first argument is an
119 anonymous array of values to be dumped. The optional second argument is an
120 anonymous array of names for the values. The names need not have a leading
121 <code>$</code> sign, and must be comprised of alphanumeric characters. You can begin
122 a name with a <code>*</code> to specify that the dereferenced type must be dumped
123 instead of the reference itself, for ARRAY and HASH references.</p>
124 </dd>
125 <dd>
126 <p>The prefix specified by <code>$Data::Dumper::Varname</code> will be used with a
127 numeric suffix if the name for a value is undefined.</p>
128 </dd>
129 <dd>
130 <p>Data::Dumper will catalog all references encountered while dumping the
131 values. Cross-references (in the form of names of substructures in perl
132 syntax) will be inserted at all possible points, preserving any structural
133 interdependencies in the original set of values. Structure traversal is
134 depth-first, and proceeds in order from the first supplied value to
135 the last.</p>
136 </dd>
137 </li>
138 <dt><strong><a name="item_dump"><em>$OBJ</em>-&gt;Dump <em>or</em> <em>PACKAGE</em>-&gt;Dump(<em>ARRAYREF [</em>, <em>ARRAYREF]</em>)</a></strong>
140 <dd>
141 <p>Returns the stringified form of the values stored in the object (preserving
142 the order in which they were supplied to <a href="#item_new"><code>new</code></a>), subject to the
143 configuration options below. In a list context, it returns a list
144 of strings corresponding to the supplied values.</p>
145 </dd>
146 <dd>
147 <p>The second form, for convenience, simply calls the <a href="#item_new"><code>new</code></a> method on its
148 arguments before dumping the object immediately.</p>
149 </dd>
150 </li>
151 <dt><strong><a name="item_seen"><em>$OBJ</em>-&gt;Seen(<em>[HASHREF]</em>)</a></strong>
153 <dd>
154 <p>Queries or adds to the internal table of already encountered references.
155 You must use <a href="#item_reset"><code>Reset</code></a> to explicitly clear the table if needed. Such
156 references are not dumped; instead, their names are inserted wherever they
157 are encountered subsequently. This is useful especially for properly
158 dumping subroutine references.</p>
159 </dd>
160 <dd>
161 <p>Expects an anonymous hash of name =&gt; value pairs. Same rules apply for names
162 as in <a href="#item_new"><code>new</code></a>. If no argument is supplied, will return the ``seen'' list of
163 name =&gt; value pairs, in a list context. Otherwise, returns the object
164 itself.</p>
165 </dd>
166 </li>
167 <dt><strong><a name="item_values"><em>$OBJ</em>-&gt;Values(<em>[ARRAYREF]</em>)</a></strong>
169 <dd>
170 <p>Queries or replaces the internal array of values that will be dumped.
171 When called without arguments, returns the values. Otherwise, returns the
172 object itself.</p>
173 </dd>
174 </li>
175 <dt><strong><a name="item_names"><em>$OBJ</em>-&gt;Names(<em>[ARRAYREF]</em>)</a></strong>
177 <dd>
178 <p>Queries or replaces the internal array of user supplied names for the values
179 that will be dumped. When called without arguments, returns the names.
180 Otherwise, returns the object itself.</p>
181 </dd>
182 </li>
183 <dt><strong><a name="item_reset"><em>$OBJ</em>-&gt;Reset</a></strong>
185 <dd>
186 <p>Clears the internal table of ``seen'' references and returns the object
187 itself.</p>
188 </dd>
189 </li>
190 </dl>
192 </p>
193 <h2><a name="functions">Functions</a></h2>
194 <dl>
195 <dt><strong><a name="item_dumper">Dumper(<em>LIST</em>)</a></strong>
197 <dd>
198 <p>Returns the stringified form of the values in the list, subject to the
199 configuration options below. The values will be named <code>$VAR</code><em>n</em> in the
200 output, where <em>n</em> is a numeric suffix. Will return a list of strings
201 in a list context.</p>
202 </dd>
203 </li>
204 </dl>
206 </p>
207 <h2><a name="configuration_variables_or_methods">Configuration Variables or Methods</a></h2>
208 <p>Several configuration variables can be used to control the kind of output
209 generated when using the procedural interface. These variables are usually
210 <code>local</code>ized in a block so that other parts of the code are not affected by
211 the change.</p>
212 <p>These variables determine the default state of the object created by calling
213 the <a href="#item_new"><code>new</code></a> method, but cannot be used to alter the state of the object
214 thereafter. The equivalent method names should be used instead to query
215 or set the internal state of the object.</p>
216 <p>The method forms return the object itself when called with arguments,
217 so that they can be chained together nicely.</p>
218 <ul>
219 <li>
220 <p>$Data::Dumper::Indent <em>or</em> <em>$OBJ</em>-&gt;Indent(<em>[NEWVAL]</em>)</p>
221 <p>Controls the style of indentation. It can be set to 0, 1, 2 or 3. Style 0
222 spews output without any newlines, indentation, or spaces between list
223 items. It is the most compact format possible that can still be called
224 valid perl. Style 1 outputs a readable form with newlines but no fancy
225 indentation (each level in the structure is simply indented by a fixed
226 amount of whitespace). Style 2 (the default) outputs a very readable form
227 which takes into account the length of hash keys (so the hash value lines
228 up). Style 3 is like style 2, but also annotates the elements of arrays
229 with their index (but the comment is on its own line, so array output
230 consumes twice the number of lines). Style 2 is the default.</p>
231 </li>
232 <li>
233 <p>$Data::Dumper::Purity <em>or</em> <em>$OBJ</em>-&gt;Purity(<em>[NEWVAL]</em>)</p>
234 <p>Controls the degree to which the output can be <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>ed to recreate the
235 supplied reference structures. Setting it to 1 will output additional perl
236 statements that will correctly recreate nested references. The default is
237 0.</p>
238 </li>
239 <li>
240 <p>$Data::Dumper::Pad <em>or</em> <em>$OBJ</em>-&gt;Pad(<em>[NEWVAL]</em>)</p>
241 <p>Specifies the string that will be prefixed to every line of the output.
242 Empty string by default.</p>
243 </li>
244 <li>
245 <p>$Data::Dumper::Varname <em>or</em> <em>$OBJ</em>-&gt;Varname(<em>[NEWVAL]</em>)</p>
246 <p>Contains the prefix to use for tagging variable names in the output. The
247 default is ``VAR''.</p>
248 </li>
249 <li>
250 <p>$Data::Dumper::Useqq <em>or</em> <em>$OBJ</em>-&gt;Useqq(<em>[NEWVAL]</em>)</p>
251 <p>When set, enables the use of double quotes for representing string values.
252 Whitespace other than space will be represented as <code>[\n\t\r]</code>, ``unsafe''
253 characters will be backslashed, and unprintable characters will be output as
254 quoted octal integers. Since setting this variable imposes a performance
255 penalty, the default is 0. <a href="#item_dump"><code>Dump()</code></a> will run slower if this flag is set,
256 since the fast XSUB implementation doesn't support it yet.</p>
257 </li>
258 <li>
259 <p>$Data::Dumper::Terse <em>or</em> <em>$OBJ</em>-&gt;Terse(<em>[NEWVAL]</em>)</p>
260 <p>When set, Data::Dumper will emit single, non-self-referential values as
261 atoms/terms rather than statements. This means that the <code>$VAR</code><em>n</em> names
262 will be avoided where possible, but be advised that such output may not
263 always be parseable by <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>.</p>
264 </li>
265 <li>
266 <p>$Data::Dumper::Freezer <em>or</em> $<em>OBJ</em>-&gt;Freezer(<em>[NEWVAL]</em>)</p>
267 <p>Can be set to a method name, or to an empty string to disable the feature.
268 Data::Dumper will invoke that method via the object before attempting to
269 stringify it. This method can alter the contents of the object (if, for
270 instance, it contains data allocated from C), and even rebless it in a
271 different package. The client is responsible for making sure the specified
272 method can be called via the object, and that the object ends up containing
273 only perl data types after the method has been called. Defaults to an empty
274 string.</p>
275 <p>If an object does not support the method specified (determined using
276 UNIVERSAL::can()) then the call will be skipped. If the method dies a
277 warning will be generated.</p>
278 </li>
279 <li>
280 <p>$Data::Dumper::Toaster <em>or</em> $<em>OBJ</em>-&gt;Toaster(<em>[NEWVAL]</em>)</p>
281 <p>Can be set to a method name, or to an empty string to disable the feature.
282 Data::Dumper will emit a method call for any objects that are to be dumped
283 using the syntax <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_bless"><code>bless(DATA, CLASS)-&gt;METHOD()</code></a>. Note that this means that
284 the method specified will have to perform any modifications required on the
285 object (like creating new state within it, and/or reblessing it in a
286 different package) and then return it. The client is responsible for making
287 sure the method can be called via the object, and that it returns a valid
288 object. Defaults to an empty string.</p>
289 </li>
290 <li>
291 <p>$Data::Dumper::Deepcopy <em>or</em> $<em>OBJ</em>-&gt;Deepcopy(<em>[NEWVAL]</em>)</p>
292 <p>Can be set to a boolean value to enable deep copies of structures.
293 Cross-referencing will then only be done when absolutely essential
294 (i.e., to break reference cycles). Default is 0.</p>
295 </li>
296 <li>
297 <p>$Data::Dumper::Quotekeys <em>or</em> $<em>OBJ</em>-&gt;Quotekeys(<em>[NEWVAL]</em>)</p>
298 <p>Can be set to a boolean value to control whether hash keys are quoted.
299 A false value will avoid quoting hash keys when it looks like a simple
300 string. Default is 1, which will always enclose hash keys in quotes.</p>
301 </li>
302 <li>
303 <p>$Data::Dumper::Bless <em>or</em> $<em>OBJ</em>-&gt;Bless(<em>[NEWVAL]</em>)</p>
304 <p>Can be set to a string that specifies an alternative to the <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_bless"><code>bless</code></a>
305 builtin operator used to create objects. A function with the specified
306 name should exist, and should accept the same arguments as the builtin.
307 Default is <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_bless"><code>bless</code></a>.</p>
308 </li>
309 <li>
310 <p>$Data::Dumper::Pair <em>or</em> $<em>OBJ</em>-&gt;Pair(<em>[NEWVAL]</em>)</p>
311 <p>Can be set to a string that specifies the separator between hash keys
312 and values. To dump nested hash, array and scalar values to JavaScript,
313 use: <code>$Data::Dumper::Pair = ' : ';</code>. Implementing <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_bless"><code>bless</code></a> in JavaScript
314 is left as an exercise for the reader.
315 A function with the specified name exists, and accepts the same arguments
316 as the builtin.</p>
317 <p>Default is: <code> =&gt; </code>.</p>
318 </li>
319 <li>
320 <p>$Data::Dumper::Maxdepth <em>or</em> $<em>OBJ</em>-&gt;Maxdepth(<em>[NEWVAL]</em>)</p>
321 <p>Can be set to a positive integer that specifies the depth beyond which
322 which we don't venture into a structure. Has no effect when
323 <code>Data::Dumper::Purity</code> is set. (Useful in debugger when we often don't
324 want to see more than enough). Default is 0, which means there is
325 no maximum depth.</p>
326 </li>
327 <li>
328 <p>$Data::Dumper::Useperl <em>or</em> $<em>OBJ</em>-&gt;Useperl(<em>[NEWVAL]</em>)</p>
329 <p>Can be set to a boolean value which controls whether the pure Perl
330 implementation of <code>Data::Dumper</code> is used. The <code>Data::Dumper</code> module is
331 a dual implementation, with almost all functionality written in both
332 pure Perl and also in XS ('C'). Since the XS version is much faster, it
333 will always be used if possible. This option lets you override the
334 default behavior, usually for testing purposes only. Default is 0, which
335 means the XS implementation will be used if possible.</p>
336 </li>
337 <li>
338 <p>$Data::Dumper::Sortkeys <em>or</em> $<em>OBJ</em>-&gt;Sortkeys(<em>[NEWVAL]</em>)</p>
339 <p>Can be set to a boolean value to control whether hash keys are dumped in
340 sorted order. A true value will cause the keys of all hashes to be
341 dumped in Perl's default sort order. Can also be set to a subroutine
342 reference which will be called for each hash that is dumped. In this
343 case <code>Data::Dumper</code> will call the subroutine once for each hash,
344 passing it the reference of the hash. The purpose of the subroutine is
345 to return a reference to an array of the keys that will be dumped, in
346 the order that they should be dumped. Using this feature, you can
347 control both the order of the keys, and which keys are actually used. In
348 other words, this subroutine acts as a filter by which you can exclude
349 certain keys from being dumped. Default is 0, which means that hash keys
350 are not sorted.</p>
351 </li>
352 <li>
353 <p>$Data::Dumper::Deparse <em>or</em> $<em>OBJ</em>-&gt;Deparse(<em>[NEWVAL]</em>)</p>
354 <p>Can be set to a boolean value to control whether code references are
355 turned into perl source code. If set to a true value, <code>B::Deparse</code>
356 will be used to get the source of the code reference. Using this option
357 will force using the Perl implementation of the dumper, since the fast
358 XSUB implementation doesn't support it.</p>
359 <p>Caution : use this option only if you know that your coderefs will be
360 properly reconstructed by <code>B::Deparse</code>.</p>
361 </li>
362 </ul>
364 </p>
365 <h2><a name="exports">Exports</a></h2>
366 <dl>
367 <dt><strong>Dumper</strong>
369 </dl>
371 </p>
372 <hr />
373 <h1><a name="examples">EXAMPLES</a></h1>
374 <p>Run these code snippets to get a quick feel for the behavior of this
375 module. When you are through with these examples, you may want to
376 add or change the various configuration variables described above,
377 to see their behavior. (See the testsuite in the Data::Dumper
378 distribution for more examples.)</p>
379 <pre>
380 use Data::Dumper;</pre>
381 <pre>
382 package Foo;
383 sub new {bless {'a' =&gt; 1, 'b' =&gt; sub { return &quot;foo&quot; }}, $_[0]};</pre>
384 <pre>
385 package Fuz; # a weird REF-REF-SCALAR object
386 sub new {bless \($_ = \ 'fu\'z'), $_[0]};</pre>
387 <pre>
388 package main;
389 $foo = Foo-&gt;new;
390 $fuz = Fuz-&gt;new;
391 $boo = [ 1, [], &quot;abcd&quot;, \*foo,
392 {1 =&gt; 'a', 023 =&gt; 'b', 0x45 =&gt; 'c'},
393 \\&quot;p\q\'r&quot;, $foo, $fuz];</pre>
394 <pre>
395 ########
396 # simple usage
397 ########</pre>
398 <pre>
399 $bar = eval(Dumper($boo));
400 print($@) if $@;
401 print Dumper($boo), Dumper($bar); # pretty print (no array indices)</pre>
402 <pre>
403 $Data::Dumper::Terse = 1; # don't output names where feasible
404 $Data::Dumper::Indent = 0; # turn off all pretty print
405 print Dumper($boo), &quot;\n&quot;;</pre>
406 <pre>
407 $Data::Dumper::Indent = 1; # mild pretty print
408 print Dumper($boo);</pre>
409 <pre>
410 $Data::Dumper::Indent = 3; # pretty print with array indices
411 print Dumper($boo);</pre>
412 <pre>
413 $Data::Dumper::Useqq = 1; # print strings in double quotes
414 print Dumper($boo);</pre>
415 <pre>
416 $Data::Dumper::Pair = &quot; : &quot;; # specify hash key/value separator
417 print Dumper($boo);</pre>
418 <pre>
419 ########
420 # recursive structures
421 ########</pre>
422 <pre>
423 @c = ('c');
424 $c = \@c;
425 $b = {};
426 $a = [1, $b, $c];
427 $b-&gt;{a} = $a;
428 $b-&gt;{b} = $a-&gt;[1];
429 $b-&gt;{c} = $a-&gt;[2];
430 print Data::Dumper-&gt;Dump([$a,$b,$c], [qw(a b c)]);</pre>
431 <pre>
432 $Data::Dumper::Purity = 1; # fill in the holes for eval
433 print Data::Dumper-&gt;Dump([$a, $b], [qw(*a b)]); # print as @a
434 print Data::Dumper-&gt;Dump([$b, $a], [qw(*b a)]); # print as %b</pre>
435 <pre>
436 $Data::Dumper::Deepcopy = 1; # avoid cross-refs
437 print Data::Dumper-&gt;Dump([$b, $a], [qw(*b a)]);</pre>
438 <pre>
439 $Data::Dumper::Purity = 0; # avoid cross-refs
440 print Data::Dumper-&gt;Dump([$b, $a], [qw(*b a)]);</pre>
441 <pre>
442 ########
443 # deep structures
444 ########</pre>
445 <pre>
446 $a = &quot;pearl&quot;;
447 $b = [ $a ];
448 $c = { 'b' =&gt; $b };
449 $d = [ $c ];
450 $e = { 'd' =&gt; $d };
451 $f = { 'e' =&gt; $e };
452 print Data::Dumper-&gt;Dump([$f], [qw(f)]);</pre>
453 <pre>
454 $Data::Dumper::Maxdepth = 3; # no deeper than 3 refs down
455 print Data::Dumper-&gt;Dump([$f], [qw(f)]);</pre>
456 <pre>
457 ########
458 # object-oriented usage
459 ########</pre>
460 <pre>
461 $d = Data::Dumper-&gt;new([$a,$b], [qw(a b)]);
462 $d-&gt;Seen({'*c' =&gt; $c}); # stash a ref without printing it
463 $d-&gt;Indent(3);
464 print $d-&gt;Dump;
465 $d-&gt;Reset-&gt;Purity(0); # empty the seen cache
466 print join &quot;----\n&quot;, $d-&gt;Dump;</pre>
467 <pre>
468 ########
469 # persistence
470 ########</pre>
471 <pre>
472 package Foo;
473 sub new { bless { state =&gt; 'awake' }, shift }
474 sub Freeze {
475 my $s = shift;
476 print STDERR &quot;preparing to sleep\n&quot;;
477 $s-&gt;{state} = 'asleep';
478 return bless $s, 'Foo::ZZZ';
479 }</pre>
480 <pre>
481 package Foo::ZZZ;
482 sub Thaw {
483 my $s = shift;
484 print STDERR &quot;waking up\n&quot;;
485 $s-&gt;{state} = 'awake';
486 return bless $s, 'Foo';
487 }</pre>
488 <pre>
489 package Foo;
490 use Data::Dumper;
491 $a = Foo-&gt;new;
492 $b = Data::Dumper-&gt;new([$a], ['c']);
493 $b-&gt;Freezer('Freeze');
494 $b-&gt;Toaster('Thaw');
495 $c = $b-&gt;Dump;
496 print $c;
497 $d = eval $c;
498 print Data::Dumper-&gt;Dump([$d], ['d']);</pre>
499 <pre>
500 ########
501 # symbol substitution (useful for recreating CODE refs)
502 ########</pre>
503 <pre>
504 sub foo { print &quot;foo speaking\n&quot; }
505 *other = \&amp;foo;
506 $bar = [ \&amp;other ];
507 $d = Data::Dumper-&gt;new([\&amp;other,$bar],['*other','bar']);
508 $d-&gt;Seen({ '*foo' =&gt; \&amp;foo });
509 print $d-&gt;Dump;</pre>
510 <pre>
511 ########
512 # sorting and filtering hash keys
513 ########</pre>
514 <pre>
515 $Data::Dumper::Sortkeys = \&amp;my_filter;
516 my $foo = { map { (ord, &quot;$_$_$_&quot;) } 'I'..'Q' };
517 my $bar = { %$foo };
518 my $baz = { reverse %$foo };
519 print Dumper [ $foo, $bar, $baz ];</pre>
520 <pre>
521 sub my_filter {
522 my ($hash) = @_;
523 # return an array ref containing the hash keys to dump
524 # in the order that you want them to be dumped
525 return [
526 # Sort the keys of %$foo in reverse numeric order
527 $hash eq $foo ? (sort {$b &lt;=&gt; $a} keys %$hash) :
528 # Only dump the odd number keys of %$bar
529 $hash eq $bar ? (grep {$_ % 2} keys %$hash) :
530 # Sort keys in default order for all other hashes
531 (sort keys %$hash)
533 }</pre>
535 </p>
536 <hr />
537 <h1><a name="bugs">BUGS</a></h1>
538 <p>Due to limitations of Perl subroutine call semantics, you cannot pass an
539 array or hash. Prepend it with a <code>\</code> to pass its reference instead. This
540 will be remedied in time, now that Perl has subroutine prototypes.
541 For now, you need to use the extended usage form, and prepend the
542 name with a <code>*</code> to output it as a hash or array.</p>
543 <p><code>Data::Dumper</code> cheats with CODE references. If a code reference is
544 encountered in the structure being processed (and if you haven't set
545 the <code>Deparse</code> flag), an anonymous subroutine that
546 contains the string '``DUMMY''' will be inserted in its place, and a warning
547 will be printed if <code>Purity</code> is set. You can <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a> the result, but bear
548 in mind that the anonymous sub that gets created is just a placeholder.
549 Someday, perl will have a switch to cache-on-demand the string
550 representation of a compiled piece of code, I hope. If you have prior
551 knowledge of all the code refs that your data structures are likely
552 to have, you can use the <a href="#item_seen"><code>Seen</code></a> method to pre-seed the internal reference
553 table and make the dumped output point to them, instead. See <a href="#examples">EXAMPLES</a>
554 above.</p>
555 <p>The <code>Useqq</code> and <code>Deparse</code> flags makes <a href="#item_dump"><code>Dump()</code></a> run slower, since the
556 XSUB implementation does not support them.</p>
557 <p>SCALAR objects have the weirdest looking <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_bless"><code>bless</code></a> workaround.</p>
558 <p>Pure Perl version of <code>Data::Dumper</code> escapes UTF-8 strings correctly
559 only in Perl 5.8.0 and later.</p>
561 </p>
562 <h2><a name="note">NOTE</a></h2>
563 <p>Starting from Perl 5.8.1 different runs of Perl will have different
564 ordering of hash keys. The change was done for greater security,
565 see <a href="file://C|\msysgit\mingw\html/pod/perlsec.html#algorithmic_complexity_attacks">Algorithmic Complexity Attacks in the perlsec manpage</a>. This means that
566 different runs of Perl will have different Data::Dumper outputs if
567 the data contains hashes. If you need to have identical Data::Dumper
568 outputs from different runs of Perl, use the environment variable
569 PERL_HASH_SEED, see <a href="file://C|\msysgit\mingw\html/pod/perlrun.html#perl_hash_seed">PERL_HASH_SEED in the perlrun manpage</a>. Using this restores
570 the old (platform-specific) ordering: an even prettier solution might
571 be to use the <code>Sortkeys</code> filter of Data::Dumper.</p>
573 </p>
574 <hr />
575 <h1><a name="author">AUTHOR</a></h1>
576 <p>Gurusamy Sarathy <a href="mailto:gsar@activestate.com">gsar@activestate.com</a></p>
577 <p>Copyright (c) 1996-98 Gurusamy Sarathy. All rights reserved.
578 This program is free software; you can redistribute it and/or
579 modify it under the same terms as Perl itself.</p>
581 </p>
582 <hr />
583 <h1><a name="version">VERSION</a></h1>
584 <p>Version 2.121 (Aug 24 2003)</p>
586 </p>
587 <hr />
588 <h1><a name="see_also">SEE ALSO</a></h1>
589 <p><code>perl(1)</code></p>
590 <table border="0" width="100%" cellspacing="0" cellpadding="3">
591 <tr><td class="block" style="background-color: #cccccc" valign="middle">
592 <big><strong><span class="block">&nbsp;Data::Dumper - stringified perl data structures, suitable for both printing and C&lt;eval&gt;</span></strong></big>
593 </td></tr>
594 </table>
596 </body>
598 </html>