Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / Data::Dumper.3
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "Data::Dumper 3"
132.TH Data::Dumper 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134Data::Dumper \- stringified perl data structures, suitable for both printing and \f(CW\*(C`eval\*(C'\fR
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 1
138\& use Data::Dumper;
139.Ve
140.PP
141.Vb 2
142\& # simple procedural interface
143\& print Dumper($foo, $bar);
144.Ve
145.PP
146.Vb 2
147\& # extended usage with names
148\& print Data::Dumper->Dump([$foo, $bar], [qw(foo *ary)]);
149.Ve
150.PP
151.Vb 5
152\& # configuration variables
153\& {
154\& local $Data::Dump::Purity = 1;
155\& eval Data::Dumper->Dump([$foo, $bar], [qw(foo *ary)]);
156\& }
157.Ve
158.PP
159.Vb 7
160\& # OO usage
161\& $d = Data::Dumper->new([$foo, $bar], [qw(foo *ary)]);
162\& ...
163\& print $d->Dump;
164\& ...
165\& $d->Purity(1)->Terse(1)->Deepcopy(1);
166\& eval $d->Dump;
167.Ve
168.SH "DESCRIPTION"
169.IX Header "DESCRIPTION"
170Given a list of scalars or reference variables, writes out their contents in
171perl syntax. The references can also be objects. The contents of each
172variable is output in a single Perl statement. Handles self-referential
173structures correctly.
174.PP
175The return value can be \f(CW\*(C`eval\*(C'\fRed to get back an identical copy of the
176original reference structure.
177.PP
178Any references that are the same as one of those passed in will be named
179\&\f(CW$VAR\fR\fIn\fR (where \fIn\fR is a numeric suffix), and other duplicate references
180to substructures within \f(CW$VAR\fR\fIn\fR will be appropriately labeled using arrow
181notation. You can specify names for individual values to be dumped if you
182use the \f(CW\*(C`Dump()\*(C'\fR method, or you can change the default \f(CW$VAR\fR prefix to
183something else. See \f(CW$Data::Dumper::Varname\fR and \f(CW$Data::Dumper::Terse\fR
184below.
185.PP
186The default output of self-referential structures can be \f(CW\*(C`eval\*(C'\fRed, but the
187nested references to \f(CW$VAR\fR\fIn\fR will be undefined, since a recursive
188structure cannot be constructed using one Perl statement. You should set the
189\&\f(CW\*(C`Purity\*(C'\fR flag to 1 to get additional statements that will correctly fill in
190these references.
191.PP
192In the extended usage form, the references to be dumped can be given
193user-specified names. If a name begins with a \f(CW\*(C`*\*(C'\fR, the output will
194describe the dereferenced type of the supplied reference for hashes and
195arrays, and coderefs. Output of names will be avoided where possible if
196the \f(CW\*(C`Terse\*(C'\fR flag is set.
197.PP
198In many cases, methods that are used to set the internal state of the
199object will return the object itself, so method calls can be conveniently
200chained together.
201.PP
202Several styles of output are possible, all controlled by setting
203the \f(CW\*(C`Indent\*(C'\fR flag. See \*(L"Configuration Variables or Methods\*(R" below
204for details.
205.Sh "Methods"
206.IX Subsection "Methods"
207.IP "\fI\s-1PACKAGE\s0\fR\->new(\fI\s-1ARRAYREF\s0 [\fR, \fI\s-1ARRAYREF\s0]\fR)" 4
208.IX Item "PACKAGE->new(ARRAYREF [, ARRAYREF])"
209Returns a newly created \f(CW\*(C`Data::Dumper\*(C'\fR object. The first argument is an
210anonymous array of values to be dumped. The optional second argument is an
211anonymous array of names for the values. The names need not have a leading
212\&\f(CW\*(C`$\*(C'\fR sign, and must be comprised of alphanumeric characters. You can begin
213a name with a \f(CW\*(C`*\*(C'\fR to specify that the dereferenced type must be dumped
214instead of the reference itself, for \s-1ARRAY\s0 and \s-1HASH\s0 references.
215.Sp
216The prefix specified by \f(CW$Data::Dumper::Varname\fR will be used with a
217numeric suffix if the name for a value is undefined.
218.Sp
219Data::Dumper will catalog all references encountered while dumping the
220values. Cross-references (in the form of names of substructures in perl
221syntax) will be inserted at all possible points, preserving any structural
222interdependencies in the original set of values. Structure traversal is
223depth\-first, and proceeds in order from the first supplied value to
224the last.
225.IP "\fI$OBJ\fR\->Dump \fIor\fR \fI\s-1PACKAGE\s0\fR\->Dump(\fI\s-1ARRAYREF\s0 [\fR, \fI\s-1ARRAYREF\s0]\fR)" 4
226.IX Item "$OBJ->Dump or PACKAGE->Dump(ARRAYREF [, ARRAYREF])"
227Returns the stringified form of the values stored in the object (preserving
228the order in which they were supplied to \f(CW\*(C`new\*(C'\fR), subject to the
229configuration options below. In a list context, it returns a list
230of strings corresponding to the supplied values.
231.Sp
232The second form, for convenience, simply calls the \f(CW\*(C`new\*(C'\fR method on its
233arguments before dumping the object immediately.
234.IP "\fI$OBJ\fR\->Seen(\fI[\s-1HASHREF\s0]\fR)" 4
235.IX Item "$OBJ->Seen([HASHREF])"
236Queries or adds to the internal table of already encountered references.
237You must use \f(CW\*(C`Reset\*(C'\fR to explicitly clear the table if needed. Such
238references are not dumped; instead, their names are inserted wherever they
239are encountered subsequently. This is useful especially for properly
240dumping subroutine references.
241.Sp
242Expects an anonymous hash of name => value pairs. Same rules apply for names
243as in \f(CW\*(C`new\*(C'\fR. If no argument is supplied, will return the \*(L"seen\*(R" list of
244name => value pairs, in a list context. Otherwise, returns the object
245itself.
246.IP "\fI$OBJ\fR\->Values(\fI[\s-1ARRAYREF\s0]\fR)" 4
247.IX Item "$OBJ->Values([ARRAYREF])"
248Queries or replaces the internal array of values that will be dumped.
249When called without arguments, returns the values. Otherwise, returns the
250object itself.
251.IP "\fI$OBJ\fR\->Names(\fI[\s-1ARRAYREF\s0]\fR)" 4
252.IX Item "$OBJ->Names([ARRAYREF])"
253Queries or replaces the internal array of user supplied names for the values
254that will be dumped. When called without arguments, returns the names.
255Otherwise, returns the object itself.
256.IP "\fI$OBJ\fR\->Reset" 4
257.IX Item "$OBJ->Reset"
258Clears the internal table of \*(L"seen\*(R" references and returns the object
259itself.
260.Sh "Functions"
261.IX Subsection "Functions"
262.IP "Dumper(\fI\s-1LIST\s0\fR)" 4
263.IX Item "Dumper(LIST)"
264Returns the stringified form of the values in the list, subject to the
265configuration options below. The values will be named \f(CW$VAR\fR\fIn\fR in the
266output, where \fIn\fR is a numeric suffix. Will return a list of strings
267in a list context.
268.Sh "Configuration Variables or Methods"
269.IX Subsection "Configuration Variables or Methods"
270Several configuration variables can be used to control the kind of output
271generated when using the procedural interface. These variables are usually
272\&\f(CW\*(C`local\*(C'\fRized in a block so that other parts of the code are not affected by
273the change.
274.PP
275These variables determine the default state of the object created by calling
276the \f(CW\*(C`new\*(C'\fR method, but cannot be used to alter the state of the object
277thereafter. The equivalent method names should be used instead to query
278or set the internal state of the object.
279.PP
280The method forms return the object itself when called with arguments,
281so that they can be chained together nicely.
282.IP "$Data::Dumper::Indent \fIor\fR \fI$OBJ\fR\->Indent(\fI[\s-1NEWVAL\s0]\fR)" 4
283.IX Item "$Data::Dumper::Indent or $OBJ->Indent([NEWVAL])"
284Controls the style of indentation. It can be set to 0, 1, 2 or 3. Style 0
285spews output without any newlines, indentation, or spaces between list
286items. It is the most compact format possible that can still be called
287valid perl. Style 1 outputs a readable form with newlines but no fancy
288indentation (each level in the structure is simply indented by a fixed
289amount of whitespace). Style 2 (the default) outputs a very readable form
290which takes into account the length of hash keys (so the hash value lines
291up). Style 3 is like style 2, but also annotates the elements of arrays
292with their index (but the comment is on its own line, so array output
293consumes twice the number of lines). Style 2 is the default.
294.IP "$Data::Dumper::Purity \fIor\fR \fI$OBJ\fR\->Purity(\fI[\s-1NEWVAL\s0]\fR)" 4
295.IX Item "$Data::Dumper::Purity or $OBJ->Purity([NEWVAL])"
296Controls the degree to which the output can be \f(CW\*(C`eval\*(C'\fRed to recreate the
297supplied reference structures. Setting it to 1 will output additional perl
298statements that will correctly recreate nested references. The default is
2990.
300.IP "$Data::Dumper::Pad \fIor\fR \fI$OBJ\fR\->Pad(\fI[\s-1NEWVAL\s0]\fR)" 4
301.IX Item "$Data::Dumper::Pad or $OBJ->Pad([NEWVAL])"
302Specifies the string that will be prefixed to every line of the output.
303Empty string by default.
304.IP "$Data::Dumper::Varname \fIor\fR \fI$OBJ\fR\->Varname(\fI[\s-1NEWVAL\s0]\fR)" 4
305.IX Item "$Data::Dumper::Varname or $OBJ->Varname([NEWVAL])"
306Contains the prefix to use for tagging variable names in the output. The
307default is \*(L"\s-1VAR\s0\*(R".
308.IP "$Data::Dumper::Useqq \fIor\fR \fI$OBJ\fR\->Useqq(\fI[\s-1NEWVAL\s0]\fR)" 4
309.IX Item "$Data::Dumper::Useqq or $OBJ->Useqq([NEWVAL])"
310When set, enables the use of double quotes for representing string values.
311Whitespace other than space will be represented as \f(CW\*(C`[\en\et\er]\*(C'\fR, \*(L"unsafe\*(R"
312characters will be backslashed, and unprintable characters will be output as
313quoted octal integers. Since setting this variable imposes a performance
314penalty, the default is 0. \f(CW\*(C`Dump()\*(C'\fR will run slower if this flag is set,
315since the fast \s-1XSUB\s0 implementation doesn't support it yet.
316.IP "$Data::Dumper::Terse \fIor\fR \fI$OBJ\fR\->Terse(\fI[\s-1NEWVAL\s0]\fR)" 4
317.IX Item "$Data::Dumper::Terse or $OBJ->Terse([NEWVAL])"
318When set, Data::Dumper will emit single, non-self-referential values as
319atoms/terms rather than statements. This means that the \f(CW$VAR\fR\fIn\fR names
320will be avoided where possible, but be advised that such output may not
321always be parseable by \f(CW\*(C`eval\*(C'\fR.
322.IP "$Data::Dumper::Freezer \fIor\fR $\fI\s-1OBJ\s0\fR\->Freezer(\fI[\s-1NEWVAL\s0]\fR)" 4
323.IX Item "$Data::Dumper::Freezer or $OBJ->Freezer([NEWVAL])"
324Can be set to a method name, or to an empty string to disable the feature.
325Data::Dumper will invoke that method via the object before attempting to
326stringify it. This method can alter the contents of the object (if, for
327instance, it contains data allocated from C), and even rebless it in a
328different package. The client is responsible for making sure the specified
329method can be called via the object, and that the object ends up containing
330only perl data types after the method has been called. Defaults to an empty
331string.
332.IP "$Data::Dumper::Toaster \fIor\fR $\fI\s-1OBJ\s0\fR\->Toaster(\fI[\s-1NEWVAL\s0]\fR)" 4
333.IX Item "$Data::Dumper::Toaster or $OBJ->Toaster([NEWVAL])"
334Can be set to a method name, or to an empty string to disable the feature.
335Data::Dumper will emit a method call for any objects that are to be dumped
336using the syntax \f(CW\*(C`bless(DATA, CLASS)\->METHOD()\*(C'\fR. Note that this means that
337the method specified will have to perform any modifications required on the
338object (like creating new state within it, and/or reblessing it in a
339different package) and then return it. The client is responsible for making
340sure the method can be called via the object, and that it returns a valid
341object. Defaults to an empty string.
342.IP "$Data::Dumper::Deepcopy \fIor\fR $\fI\s-1OBJ\s0\fR\->Deepcopy(\fI[\s-1NEWVAL\s0]\fR)" 4
343.IX Item "$Data::Dumper::Deepcopy or $OBJ->Deepcopy([NEWVAL])"
344Can be set to a boolean value to enable deep copies of structures.
345Cross-referencing will then only be done when absolutely essential
346(i.e., to break reference cycles). Default is 0.
347.IP "$Data::Dumper::Quotekeys \fIor\fR $\fI\s-1OBJ\s0\fR\->Quotekeys(\fI[\s-1NEWVAL\s0]\fR)" 4
348.IX Item "$Data::Dumper::Quotekeys or $OBJ->Quotekeys([NEWVAL])"
349Can be set to a boolean value to control whether hash keys are quoted.
350A false value will avoid quoting hash keys when it looks like a simple
351string. Default is 1, which will always enclose hash keys in quotes.
352.IP "$Data::Dumper::Bless \fIor\fR $\fI\s-1OBJ\s0\fR\->Bless(\fI[\s-1NEWVAL\s0]\fR)" 4
353.IX Item "$Data::Dumper::Bless or $OBJ->Bless([NEWVAL])"
354Can be set to a string that specifies an alternative to the \f(CW\*(C`bless\*(C'\fR
355builtin operator used to create objects. A function with the specified
356name should exist, and should accept the same arguments as the builtin.
357Default is \f(CW\*(C`bless\*(C'\fR.
358.IP "$Data::Dumper::Maxdepth \fIor\fR $\fI\s-1OBJ\s0\fR\->Maxdepth(\fI[\s-1NEWVAL\s0]\fR)" 4
359.IX Item "$Data::Dumper::Maxdepth or $OBJ->Maxdepth([NEWVAL])"
360Can be set to a positive integer that specifies the depth beyond which
361which we don't venture into a structure. Has no effect when
362\&\f(CW\*(C`Data::Dumper::Purity\*(C'\fR is set. (Useful in debugger when we often don't
363want to see more than enough). Default is 0, which means there is
364no maximum depth.
365.IP "$Data::Dumper::Useperl \fIor\fR $\fI\s-1OBJ\s0\fR\->Useperl(\fI[\s-1NEWVAL\s0]\fR)" 4
366.IX Item "$Data::Dumper::Useperl or $OBJ->Useperl([NEWVAL])"
367Can be set to a boolean value which controls whether the pure Perl
368implementation of \f(CW\*(C`Data::Dumper\*(C'\fR is used. The \f(CW\*(C`Data::Dumper\*(C'\fR module is
369a dual implementation, with almost all functionality written in both
370pure Perl and also in \s-1XS\s0 ('C'). Since the \s-1XS\s0 version is much faster, it
371will always be used if possible. This option lets you override the
372default behavior, usually for testing purposes only. Default is 0, which
373means the \s-1XS\s0 implementation will be used if possible.
374.IP "$Data::Dumper::Sortkeys \fIor\fR $\fI\s-1OBJ\s0\fR\->Sortkeys(\fI[\s-1NEWVAL\s0]\fR)" 4
375.IX Item "$Data::Dumper::Sortkeys or $OBJ->Sortkeys([NEWVAL])"
376Can be set to a boolean value to control whether hash keys are dumped in
377sorted order. A true value will cause the keys of all hashes to be
378dumped in Perl's default sort order. Can also be set to a subroutine
379reference which will be called for each hash that is dumped. In this
380case \f(CW\*(C`Data::Dumper\*(C'\fR will call the subroutine once for each hash,
381passing it the reference of the hash. The purpose of the subroutine is
382to return a reference to an array of the keys that will be dumped, in
383the order that they should be dumped. Using this feature, you can
384control both the order of the keys, and which keys are actually used. In
385other words, this subroutine acts as a filter by which you can exclude
386certain keys from being dumped. Default is 0, which means that hash keys
387are not sorted.
388.IP "$Data::Dumper::Deparse \fIor\fR $\fI\s-1OBJ\s0\fR\->Deparse(\fI[\s-1NEWVAL\s0]\fR)" 4
389.IX Item "$Data::Dumper::Deparse or $OBJ->Deparse([NEWVAL])"
390Can be set to a boolean value to control whether code references are
391turned into perl source code. If set to a true value, \f(CW\*(C`B::Deparse\*(C'\fR
392will be used to get the source of the code reference. Using this option
393will force using the Perl implementation of the dumper, since the fast
394\&\s-1XSUB\s0 implementation doesn't support it.
395.Sp
396Caution : use this option only if you know that your coderefs will be
397properly reconstructed by \f(CW\*(C`B::Deparse\*(C'\fR.
398.Sh "Exports"
399.IX Subsection "Exports"
400.IP "Dumper" 4
401.IX Item "Dumper"
402.SH "EXAMPLES"
403.IX Header "EXAMPLES"
404Run these code snippets to get a quick feel for the behavior of this
405module. When you are through with these examples, you may want to
406add or change the various configuration variables described above,
407to see their behavior. (See the testsuite in the Data::Dumper
408distribution for more examples.)
409.PP
410.Vb 1
411\& use Data::Dumper;
412.Ve
413.PP
414.Vb 2
415\& package Foo;
416\& sub new {bless {'a' => 1, 'b' => sub { return "foo" }}, $_[0]};
417.Ve
418.PP
419.Vb 2
420\& package Fuz; # a weird REF-REF-SCALAR object
421\& sub new {bless \e($_ = \e 'fu\e'z'), $_[0]};
422.Ve
423.PP
424.Vb 6
425\& package main;
426\& $foo = Foo->new;
427\& $fuz = Fuz->new;
428\& $boo = [ 1, [], "abcd", \e*foo,
429\& {1 => 'a', 023 => 'b', 0x45 => 'c'},
430\& \e\e"p\eq\e'r", $foo, $fuz];
431.Ve
432.PP
433.Vb 3
434\& ########
435\& # simple usage
436\& ########
437.Ve
438.PP
439.Vb 3
440\& $bar = eval(Dumper($boo));
441\& print($@) if $@;
442\& print Dumper($boo), Dumper($bar); # pretty print (no array indices)
443.Ve
444.PP
445.Vb 3
446\& $Data::Dumper::Terse = 1; # don't output names where feasible
447\& $Data::Dumper::Indent = 0; # turn off all pretty print
448\& print Dumper($boo), "\en";
449.Ve
450.PP
451.Vb 2
452\& $Data::Dumper::Indent = 1; # mild pretty print
453\& print Dumper($boo);
454.Ve
455.PP
456.Vb 2
457\& $Data::Dumper::Indent = 3; # pretty print with array indices
458\& print Dumper($boo);
459.Ve
460.PP
461.Vb 2
462\& $Data::Dumper::Useqq = 1; # print strings in double quotes
463\& print Dumper($boo);
464.Ve
465.PP
466.Vb 3
467\& ########
468\& # recursive structures
469\& ########
470.Ve
471.PP
472.Vb 8
473\& @c = ('c');
474\& $c = \e@c;
475\& $b = {};
476\& $a = [1, $b, $c];
477\& $b->{a} = $a;
478\& $b->{b} = $a->[1];
479\& $b->{c} = $a->[2];
480\& print Data::Dumper->Dump([$a,$b,$c], [qw(a b c)]);
481.Ve
482.PP
483.Vb 3
484\& $Data::Dumper::Purity = 1; # fill in the holes for eval
485\& print Data::Dumper->Dump([$a, $b], [qw(*a b)]); # print as @a
486\& print Data::Dumper->Dump([$b, $a], [qw(*b a)]); # print as %b
487.Ve
488.PP
489.Vb 2
490\& $Data::Dumper::Deepcopy = 1; # avoid cross-refs
491\& print Data::Dumper->Dump([$b, $a], [qw(*b a)]);
492.Ve
493.PP
494.Vb 2
495\& $Data::Dumper::Purity = 0; # avoid cross-refs
496\& print Data::Dumper->Dump([$b, $a], [qw(*b a)]);
497.Ve
498.PP
499.Vb 3
500\& ########
501\& # deep structures
502\& ########
503.Ve
504.PP
505.Vb 7
506\& $a = "pearl";
507\& $b = [ $a ];
508\& $c = { 'b' => $b };
509\& $d = [ $c ];
510\& $e = { 'd' => $d };
511\& $f = { 'e' => $e };
512\& print Data::Dumper->Dump([$f], [qw(f)]);
513.Ve
514.PP
515.Vb 2
516\& $Data::Dumper::Maxdepth = 3; # no deeper than 3 refs down
517\& print Data::Dumper->Dump([$f], [qw(f)]);
518.Ve
519.PP
520.Vb 3
521\& ########
522\& # object-oriented usage
523\& ########
524.Ve
525.PP
526.Vb 6
527\& $d = Data::Dumper->new([$a,$b], [qw(a b)]);
528\& $d->Seen({'*c' => $c}); # stash a ref without printing it
529\& $d->Indent(3);
530\& print $d->Dump;
531\& $d->Reset->Purity(0); # empty the seen cache
532\& print join "----\en", $d->Dump;
533.Ve
534.PP
535.Vb 3
536\& ########
537\& # persistence
538\& ########
539.Ve
540.PP
541.Vb 8
542\& package Foo;
543\& sub new { bless { state => 'awake' }, shift }
544\& sub Freeze {
545\& my $s = shift;
546\& print STDERR "preparing to sleep\en";
547\& $s->{state} = 'asleep';
548\& return bless $s, 'Foo::ZZZ';
549\& }
550.Ve
551.PP
552.Vb 7
553\& package Foo::ZZZ;
554\& sub Thaw {
555\& my $s = shift;
556\& print STDERR "waking up\en";
557\& $s->{state} = 'awake';
558\& return bless $s, 'Foo';
559\& }
560.Ve
561.PP
562.Vb 10
563\& package Foo;
564\& use Data::Dumper;
565\& $a = Foo->new;
566\& $b = Data::Dumper->new([$a], ['c']);
567\& $b->Freezer('Freeze');
568\& $b->Toaster('Thaw');
569\& $c = $b->Dump;
570\& print $c;
571\& $d = eval $c;
572\& print Data::Dumper->Dump([$d], ['d']);
573.Ve
574.PP
575.Vb 3
576\& ########
577\& # symbol substitution (useful for recreating CODE refs)
578\& ########
579.Ve
580.PP
581.Vb 6
582\& sub foo { print "foo speaking\en" }
583\& *other = \e&foo;
584\& $bar = [ \e&other ];
585\& $d = Data::Dumper->new([\e&other,$bar],['*other','bar']);
586\& $d->Seen({ '*foo' => \e&foo });
587\& print $d->Dump;
588.Ve
589.PP
590.Vb 3
591\& ########
592\& # sorting and filtering hash keys
593\& ########
594.Ve
595.PP
596.Vb 5
597\& $Data::Dumper::Sortkeys = \e&my_filter;
598\& my $foo = { map { (ord, "$_$_$_") } 'I'..'Q' };
599\& my $bar = { %$foo };
600\& my $baz = { reverse %$foo };
601\& print Dumper [ $foo, $bar, $baz ];
602.Ve
603.PP
604.Vb 13
605\& sub my_filter {
606\& my ($hash) = @_;
607\& # return an array ref containing the hash keys to dump
608\& # in the order that you want them to be dumped
609\& return [
610\& # Sort the keys of %$foo in reverse numeric order
611\& $hash eq $foo ? (sort {$b <=> $a} keys %$hash) :
612\& # Only dump the odd number keys of %$bar
613\& $hash eq $bar ? (grep {$_ % 2} keys %$hash) :
614\& # Sort keys in default order for all other hashes
615\& (sort keys %$hash)
616\& ];
617\& }
618.Ve
619.SH "BUGS"
620.IX Header "BUGS"
621Due to limitations of Perl subroutine call semantics, you cannot pass an
622array or hash. Prepend it with a \f(CW\*(C`\e\*(C'\fR to pass its reference instead. This
623will be remedied in time, now that Perl has subroutine prototypes.
624For now, you need to use the extended usage form, and prepend the
625name with a \f(CW\*(C`*\*(C'\fR to output it as a hash or array.
626.PP
627\&\f(CW\*(C`Data::Dumper\*(C'\fR cheats with \s-1CODE\s0 references. If a code reference is
628encountered in the structure being processed (and if you haven't set
629the \f(CW\*(C`Deparse\*(C'\fR flag), an anonymous subroutine that
630contains the string '\*(L"\s-1DUMMY\s0\*(R"' will be inserted in its place, and a warning
631will be printed if \f(CW\*(C`Purity\*(C'\fR is set. You can \f(CW\*(C`eval\*(C'\fR the result, but bear
632in mind that the anonymous sub that gets created is just a placeholder.
633Someday, perl will have a switch to cache-on-demand the string
634representation of a compiled piece of code, I hope. If you have prior
635knowledge of all the code refs that your data structures are likely
636to have, you can use the \f(CW\*(C`Seen\*(C'\fR method to pre-seed the internal reference
637table and make the dumped output point to them, instead. See \s-1EXAMPLES\s0
638above.
639.PP
640The \f(CW\*(C`Useqq\*(C'\fR and \f(CW\*(C`Deparse\*(C'\fR flags makes \fIDump()\fR run slower, since the
641\&\s-1XSUB\s0 implementation does not support them.
642.PP
643\&\s-1SCALAR\s0 objects have the weirdest looking \f(CW\*(C`bless\*(C'\fR workaround.
644.SH "AUTHOR"
645.IX Header "AUTHOR"
646Gurusamy Sarathy gsar@activestate.com
647.PP
648Copyright (c) 1996\-98 Gurusamy Sarathy. All rights reserved.
649This program is free software; you can redistribute it and/or
650modify it under the same terms as Perl itself.
651.SH "VERSION"
652.IX Header "VERSION"
653Version 2.12 (unreleased)
654.SH "SEE ALSO"
655.IX Header "SEE ALSO"
656\&\fIperl\fR\|(1)