Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 |
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 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | Data::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::Dumper::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" | |
170 | Given a list of scalars or reference variables, writes out their contents in | |
171 | perl syntax. The references can also be objects. The contents of each | |
172 | variable is output in a single Perl statement. Handles self-referential | |
173 | structures correctly. | |
174 | .PP | |
175 | The return value can be \f(CW\*(C`eval\*(C'\fRed to get back an identical copy of the | |
176 | original reference structure. | |
177 | .PP | |
178 | Any 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 | |
180 | to substructures within \f(CW$VAR\fR\fIn\fR will be appropriately labeled using arrow | |
181 | notation. You can specify names for individual values to be dumped if you | |
182 | use the \f(CW\*(C`Dump()\*(C'\fR method, or you can change the default \f(CW$VAR\fR prefix to | |
183 | something else. See \f(CW$Data::Dumper::Varname\fR and \f(CW$Data::Dumper::Terse\fR | |
184 | below. | |
185 | .PP | |
186 | The default output of self-referential structures can be \f(CW\*(C`eval\*(C'\fRed, but the | |
187 | nested references to \f(CW$VAR\fR\fIn\fR will be undefined, since a recursive | |
188 | structure 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 | |
190 | these references. Moreover, if \f(CW\*(C`eval\*(C'\fRed when strictures are in effect, | |
191 | you need to ensure that any variables it accesses are previously declared. | |
192 | .PP | |
193 | In the extended usage form, the references to be dumped can be given | |
194 | user-specified names. If a name begins with a \f(CW\*(C`*\*(C'\fR, the output will | |
195 | describe the dereferenced type of the supplied reference for hashes and | |
196 | arrays, and coderefs. Output of names will be avoided where possible if | |
197 | the \f(CW\*(C`Terse\*(C'\fR flag is set. | |
198 | .PP | |
199 | In many cases, methods that are used to set the internal state of the | |
200 | object will return the object itself, so method calls can be conveniently | |
201 | chained together. | |
202 | .PP | |
203 | Several styles of output are possible, all controlled by setting | |
204 | the \f(CW\*(C`Indent\*(C'\fR flag. See \*(L"Configuration Variables or Methods\*(R" below | |
205 | for details. | |
206 | .Sh "Methods" | |
207 | .IX Subsection "Methods" | |
208 | .IP "\fI\s-1PACKAGE\s0\fR\->new(\fI\s-1ARRAYREF\s0 [\fR, \fI\s-1ARRAYREF\s0]\fR)" 4 | |
209 | .IX Item "PACKAGE->new(ARRAYREF [, ARRAYREF])" | |
210 | Returns a newly created \f(CW\*(C`Data::Dumper\*(C'\fR object. The first argument is an | |
211 | anonymous array of values to be dumped. The optional second argument is an | |
212 | anonymous array of names for the values. The names need not have a leading | |
213 | \&\f(CW\*(C`$\*(C'\fR sign, and must be comprised of alphanumeric characters. You can begin | |
214 | a name with a \f(CW\*(C`*\*(C'\fR to specify that the dereferenced type must be dumped | |
215 | instead of the reference itself, for \s-1ARRAY\s0 and \s-1HASH\s0 references. | |
216 | .Sp | |
217 | The prefix specified by \f(CW$Data::Dumper::Varname\fR will be used with a | |
218 | numeric suffix if the name for a value is undefined. | |
219 | .Sp | |
220 | Data::Dumper will catalog all references encountered while dumping the | |
221 | values. Cross-references (in the form of names of substructures in perl | |
222 | syntax) will be inserted at all possible points, preserving any structural | |
223 | interdependencies in the original set of values. Structure traversal is | |
224 | depth\-first, and proceeds in order from the first supplied value to | |
225 | the last. | |
226 | .IP "\fI$OBJ\fR\->Dump \fIor\fR \fI\s-1PACKAGE\s0\fR\->Dump(\fI\s-1ARRAYREF\s0 [\fR, \fI\s-1ARRAYREF\s0]\fR)" 4 | |
227 | .IX Item "$OBJ->Dump or PACKAGE->Dump(ARRAYREF [, ARRAYREF])" | |
228 | Returns the stringified form of the values stored in the object (preserving | |
229 | the order in which they were supplied to \f(CW\*(C`new\*(C'\fR), subject to the | |
230 | configuration options below. In a list context, it returns a list | |
231 | of strings corresponding to the supplied values. | |
232 | .Sp | |
233 | The second form, for convenience, simply calls the \f(CW\*(C`new\*(C'\fR method on its | |
234 | arguments before dumping the object immediately. | |
235 | .IP "\fI$OBJ\fR\->Seen(\fI[\s-1HASHREF\s0]\fR)" 4 | |
236 | .IX Item "$OBJ->Seen([HASHREF])" | |
237 | Queries or adds to the internal table of already encountered references. | |
238 | You must use \f(CW\*(C`Reset\*(C'\fR to explicitly clear the table if needed. Such | |
239 | references are not dumped; instead, their names are inserted wherever they | |
240 | are encountered subsequently. This is useful especially for properly | |
241 | dumping subroutine references. | |
242 | .Sp | |
243 | Expects an anonymous hash of name => value pairs. Same rules apply for names | |
244 | as in \f(CW\*(C`new\*(C'\fR. If no argument is supplied, will return the \*(L"seen\*(R" list of | |
245 | name => value pairs, in a list context. Otherwise, returns the object | |
246 | itself. | |
247 | .IP "\fI$OBJ\fR\->Values(\fI[\s-1ARRAYREF\s0]\fR)" 4 | |
248 | .IX Item "$OBJ->Values([ARRAYREF])" | |
249 | Queries or replaces the internal array of values that will be dumped. | |
250 | When called without arguments, returns the values. Otherwise, returns the | |
251 | object itself. | |
252 | .IP "\fI$OBJ\fR\->Names(\fI[\s-1ARRAYREF\s0]\fR)" 4 | |
253 | .IX Item "$OBJ->Names([ARRAYREF])" | |
254 | Queries or replaces the internal array of user supplied names for the values | |
255 | that will be dumped. When called without arguments, returns the names. | |
256 | Otherwise, returns the object itself. | |
257 | .IP "\fI$OBJ\fR\->Reset" 4 | |
258 | .IX Item "$OBJ->Reset" | |
259 | Clears the internal table of \*(L"seen\*(R" references and returns the object | |
260 | itself. | |
261 | .Sh "Functions" | |
262 | .IX Subsection "Functions" | |
263 | .IP "Dumper(\fI\s-1LIST\s0\fR)" 4 | |
264 | .IX Item "Dumper(LIST)" | |
265 | Returns the stringified form of the values in the list, subject to the | |
266 | configuration options below. The values will be named \f(CW$VAR\fR\fIn\fR in the | |
267 | output, where \fIn\fR is a numeric suffix. Will return a list of strings | |
268 | in a list context. | |
269 | .Sh "Configuration Variables or Methods" | |
270 | .IX Subsection "Configuration Variables or Methods" | |
271 | Several configuration variables can be used to control the kind of output | |
272 | generated when using the procedural interface. These variables are usually | |
273 | \&\f(CW\*(C`local\*(C'\fRized in a block so that other parts of the code are not affected by | |
274 | the change. | |
275 | .PP | |
276 | These variables determine the default state of the object created by calling | |
277 | the \f(CW\*(C`new\*(C'\fR method, but cannot be used to alter the state of the object | |
278 | thereafter. The equivalent method names should be used instead to query | |
279 | or set the internal state of the object. | |
280 | .PP | |
281 | The method forms return the object itself when called with arguments, | |
282 | so that they can be chained together nicely. | |
283 | .IP "\(bu" 4 | |
284 | $Data::Dumper::Indent \fIor\fR \fI$OBJ\fR\->Indent(\fI[\s-1NEWVAL\s0]\fR) | |
285 | .Sp | |
286 | Controls the style of indentation. It can be set to 0, 1, 2 or 3. Style 0 | |
287 | spews output without any newlines, indentation, or spaces between list | |
288 | items. It is the most compact format possible that can still be called | |
289 | valid perl. Style 1 outputs a readable form with newlines but no fancy | |
290 | indentation (each level in the structure is simply indented by a fixed | |
291 | amount of whitespace). Style 2 (the default) outputs a very readable form | |
292 | which takes into account the length of hash keys (so the hash value lines | |
293 | up). Style 3 is like style 2, but also annotates the elements of arrays | |
294 | with their index (but the comment is on its own line, so array output | |
295 | consumes twice the number of lines). Style 2 is the default. | |
296 | .IP "\(bu" 4 | |
297 | $Data::Dumper::Purity \fIor\fR \fI$OBJ\fR\->Purity(\fI[\s-1NEWVAL\s0]\fR) | |
298 | .Sp | |
299 | Controls the degree to which the output can be \f(CW\*(C`eval\*(C'\fRed to recreate the | |
300 | supplied reference structures. Setting it to 1 will output additional perl | |
301 | statements that will correctly recreate nested references. The default is | |
302 | 0. | |
303 | .IP "\(bu" 4 | |
304 | $Data::Dumper::Pad \fIor\fR \fI$OBJ\fR\->Pad(\fI[\s-1NEWVAL\s0]\fR) | |
305 | .Sp | |
306 | Specifies the string that will be prefixed to every line of the output. | |
307 | Empty string by default. | |
308 | .IP "\(bu" 4 | |
309 | $Data::Dumper::Varname \fIor\fR \fI$OBJ\fR\->Varname(\fI[\s-1NEWVAL\s0]\fR) | |
310 | .Sp | |
311 | Contains the prefix to use for tagging variable names in the output. The | |
312 | default is \*(L"\s-1VAR\s0\*(R". | |
313 | .IP "\(bu" 4 | |
314 | $Data::Dumper::Useqq \fIor\fR \fI$OBJ\fR\->Useqq(\fI[\s-1NEWVAL\s0]\fR) | |
315 | .Sp | |
316 | When set, enables the use of double quotes for representing string values. | |
317 | Whitespace other than space will be represented as \f(CW\*(C`[\en\et\er]\*(C'\fR, \*(L"unsafe\*(R" | |
318 | characters will be backslashed, and unprintable characters will be output as | |
319 | quoted octal integers. Since setting this variable imposes a performance | |
320 | penalty, the default is 0. \f(CW\*(C`Dump()\*(C'\fR will run slower if this flag is set, | |
321 | since the fast \s-1XSUB\s0 implementation doesn't support it yet. | |
322 | .IP "\(bu" 4 | |
323 | $Data::Dumper::Terse \fIor\fR \fI$OBJ\fR\->Terse(\fI[\s-1NEWVAL\s0]\fR) | |
324 | .Sp | |
325 | When set, Data::Dumper will emit single, non-self-referential values as | |
326 | atoms/terms rather than statements. This means that the \f(CW$VAR\fR\fIn\fR names | |
327 | will be avoided where possible, but be advised that such output may not | |
328 | always be parseable by \f(CW\*(C`eval\*(C'\fR. | |
329 | .IP "\(bu" 4 | |
330 | $Data::Dumper::Freezer \fIor\fR $\fI\s-1OBJ\s0\fR\->Freezer(\fI[\s-1NEWVAL\s0]\fR) | |
331 | .Sp | |
332 | Can be set to a method name, or to an empty string to disable the feature. | |
333 | Data::Dumper will invoke that method via the object before attempting to | |
334 | stringify it. This method can alter the contents of the object (if, for | |
335 | instance, it contains data allocated from C), and even rebless it in a | |
336 | different package. The client is responsible for making sure the specified | |
337 | method can be called via the object, and that the object ends up containing | |
338 | only perl data types after the method has been called. Defaults to an empty | |
339 | string. | |
340 | .Sp | |
341 | If an object does not support the method specified (determined using | |
342 | \&\fIUNIVERSAL::can()\fR) then the call will be skipped. If the method dies a | |
343 | warning will be generated. | |
344 | .IP "\(bu" 4 | |
345 | $Data::Dumper::Toaster \fIor\fR $\fI\s-1OBJ\s0\fR\->Toaster(\fI[\s-1NEWVAL\s0]\fR) | |
346 | .Sp | |
347 | Can be set to a method name, or to an empty string to disable the feature. | |
348 | Data::Dumper will emit a method call for any objects that are to be dumped | |
349 | using the syntax \f(CW\*(C`bless(DATA, CLASS)\->METHOD()\*(C'\fR. Note that this means that | |
350 | the method specified will have to perform any modifications required on the | |
351 | object (like creating new state within it, and/or reblessing it in a | |
352 | different package) and then return it. The client is responsible for making | |
353 | sure the method can be called via the object, and that it returns a valid | |
354 | object. Defaults to an empty string. | |
355 | .IP "\(bu" 4 | |
356 | $Data::Dumper::Deepcopy \fIor\fR $\fI\s-1OBJ\s0\fR\->Deepcopy(\fI[\s-1NEWVAL\s0]\fR) | |
357 | .Sp | |
358 | Can be set to a boolean value to enable deep copies of structures. | |
359 | Cross-referencing will then only be done when absolutely essential | |
360 | (i.e., to break reference cycles). Default is 0. | |
361 | .IP "\(bu" 4 | |
362 | $Data::Dumper::Quotekeys \fIor\fR $\fI\s-1OBJ\s0\fR\->Quotekeys(\fI[\s-1NEWVAL\s0]\fR) | |
363 | .Sp | |
364 | Can be set to a boolean value to control whether hash keys are quoted. | |
365 | A false value will avoid quoting hash keys when it looks like a simple | |
366 | string. Default is 1, which will always enclose hash keys in quotes. | |
367 | .IP "\(bu" 4 | |
368 | $Data::Dumper::Bless \fIor\fR $\fI\s-1OBJ\s0\fR\->Bless(\fI[\s-1NEWVAL\s0]\fR) | |
369 | .Sp | |
370 | Can be set to a string that specifies an alternative to the \f(CW\*(C`bless\*(C'\fR | |
371 | builtin operator used to create objects. A function with the specified | |
372 | name should exist, and should accept the same arguments as the builtin. | |
373 | Default is \f(CW\*(C`bless\*(C'\fR. | |
374 | .IP "\(bu" 4 | |
375 | $Data::Dumper::Pair \fIor\fR $\fI\s-1OBJ\s0\fR\->Pair(\fI[\s-1NEWVAL\s0]\fR) | |
376 | .Sp | |
377 | Can be set to a string that specifies the separator between hash keys | |
378 | and values. To dump nested hash, array and scalar values to JavaScript, | |
379 | use: \f(CW\*(C`$Data::Dumper::Pair = ' : ';\*(C'\fR. Implementing \f(CW\*(C`bless\*(C'\fR in JavaScript | |
380 | is left as an exercise for the reader. | |
381 | A function with the specified name exists, and accepts the same arguments | |
382 | as the builtin. | |
383 | .Sp | |
384 | Default is: \f(CW\*(C` => \*(C'\fR. | |
385 | .IP "\(bu" 4 | |
386 | $Data::Dumper::Maxdepth \fIor\fR $\fI\s-1OBJ\s0\fR\->Maxdepth(\fI[\s-1NEWVAL\s0]\fR) | |
387 | .Sp | |
388 | Can be set to a positive integer that specifies the depth beyond which | |
389 | which we don't venture into a structure. Has no effect when | |
390 | \&\f(CW\*(C`Data::Dumper::Purity\*(C'\fR is set. (Useful in debugger when we often don't | |
391 | want to see more than enough). Default is 0, which means there is | |
392 | no maximum depth. | |
393 | .IP "\(bu" 4 | |
394 | $Data::Dumper::Useperl \fIor\fR $\fI\s-1OBJ\s0\fR\->Useperl(\fI[\s-1NEWVAL\s0]\fR) | |
395 | .Sp | |
396 | Can be set to a boolean value which controls whether the pure Perl | |
397 | implementation of \f(CW\*(C`Data::Dumper\*(C'\fR is used. The \f(CW\*(C`Data::Dumper\*(C'\fR module is | |
398 | a dual implementation, with almost all functionality written in both | |
399 | pure Perl and also in \s-1XS\s0 ('C'). Since the \s-1XS\s0 version is much faster, it | |
400 | will always be used if possible. This option lets you override the | |
401 | default behavior, usually for testing purposes only. Default is 0, which | |
402 | means the \s-1XS\s0 implementation will be used if possible. | |
403 | .IP "\(bu" 4 | |
404 | $Data::Dumper::Sortkeys \fIor\fR $\fI\s-1OBJ\s0\fR\->Sortkeys(\fI[\s-1NEWVAL\s0]\fR) | |
405 | .Sp | |
406 | Can be set to a boolean value to control whether hash keys are dumped in | |
407 | sorted order. A true value will cause the keys of all hashes to be | |
408 | dumped in Perl's default sort order. Can also be set to a subroutine | |
409 | reference which will be called for each hash that is dumped. In this | |
410 | case \f(CW\*(C`Data::Dumper\*(C'\fR will call the subroutine once for each hash, | |
411 | passing it the reference of the hash. The purpose of the subroutine is | |
412 | to return a reference to an array of the keys that will be dumped, in | |
413 | the order that they should be dumped. Using this feature, you can | |
414 | control both the order of the keys, and which keys are actually used. In | |
415 | other words, this subroutine acts as a filter by which you can exclude | |
416 | certain keys from being dumped. Default is 0, which means that hash keys | |
417 | are not sorted. | |
418 | .IP "\(bu" 4 | |
419 | $Data::Dumper::Deparse \fIor\fR $\fI\s-1OBJ\s0\fR\->Deparse(\fI[\s-1NEWVAL\s0]\fR) | |
420 | .Sp | |
421 | Can be set to a boolean value to control whether code references are | |
422 | turned into perl source code. If set to a true value, \f(CW\*(C`B::Deparse\*(C'\fR | |
423 | will be used to get the source of the code reference. Using this option | |
424 | will force using the Perl implementation of the dumper, since the fast | |
425 | \&\s-1XSUB\s0 implementation doesn't support it. | |
426 | .Sp | |
427 | Caution : use this option only if you know that your coderefs will be | |
428 | properly reconstructed by \f(CW\*(C`B::Deparse\*(C'\fR. | |
429 | .Sh "Exports" | |
430 | .IX Subsection "Exports" | |
431 | .IP "Dumper" 4 | |
432 | .IX Item "Dumper" | |
433 | .SH "EXAMPLES" | |
434 | .IX Header "EXAMPLES" | |
435 | Run these code snippets to get a quick feel for the behavior of this | |
436 | module. When you are through with these examples, you may want to | |
437 | add or change the various configuration variables described above, | |
438 | to see their behavior. (See the testsuite in the Data::Dumper | |
439 | distribution for more examples.) | |
440 | .PP | |
441 | .Vb 1 | |
442 | \& use Data::Dumper; | |
443 | .Ve | |
444 | .PP | |
445 | .Vb 2 | |
446 | \& package Foo; | |
447 | \& sub new {bless {'a' => 1, 'b' => sub { return "foo" }}, $_[0]}; | |
448 | .Ve | |
449 | .PP | |
450 | .Vb 2 | |
451 | \& package Fuz; # a weird REF-REF-SCALAR object | |
452 | \& sub new {bless \e($_ = \e 'fu\e'z'), $_[0]}; | |
453 | .Ve | |
454 | .PP | |
455 | .Vb 6 | |
456 | \& package main; | |
457 | \& $foo = Foo->new; | |
458 | \& $fuz = Fuz->new; | |
459 | \& $boo = [ 1, [], "abcd", \e*foo, | |
460 | \& {1 => 'a', 023 => 'b', 0x45 => 'c'}, | |
461 | \& \e\e"p\eq\e'r", $foo, $fuz]; | |
462 | .Ve | |
463 | .PP | |
464 | .Vb 3 | |
465 | \& ######## | |
466 | \& # simple usage | |
467 | \& ######## | |
468 | .Ve | |
469 | .PP | |
470 | .Vb 3 | |
471 | \& $bar = eval(Dumper($boo)); | |
472 | \& print($@) if $@; | |
473 | \& print Dumper($boo), Dumper($bar); # pretty print (no array indices) | |
474 | .Ve | |
475 | .PP | |
476 | .Vb 3 | |
477 | \& $Data::Dumper::Terse = 1; # don't output names where feasible | |
478 | \& $Data::Dumper::Indent = 0; # turn off all pretty print | |
479 | \& print Dumper($boo), "\en"; | |
480 | .Ve | |
481 | .PP | |
482 | .Vb 2 | |
483 | \& $Data::Dumper::Indent = 1; # mild pretty print | |
484 | \& print Dumper($boo); | |
485 | .Ve | |
486 | .PP | |
487 | .Vb 2 | |
488 | \& $Data::Dumper::Indent = 3; # pretty print with array indices | |
489 | \& print Dumper($boo); | |
490 | .Ve | |
491 | .PP | |
492 | .Vb 2 | |
493 | \& $Data::Dumper::Useqq = 1; # print strings in double quotes | |
494 | \& print Dumper($boo); | |
495 | .Ve | |
496 | .PP | |
497 | .Vb 2 | |
498 | \& $Data::Dumper::Pair = " : "; # specify hash key/value separator | |
499 | \& print Dumper($boo); | |
500 | .Ve | |
501 | .PP | |
502 | .Vb 3 | |
503 | \& ######## | |
504 | \& # recursive structures | |
505 | \& ######## | |
506 | .Ve | |
507 | .PP | |
508 | .Vb 8 | |
509 | \& @c = ('c'); | |
510 | \& $c = \e@c; | |
511 | \& $b = {}; | |
512 | \& $a = [1, $b, $c]; | |
513 | \& $b->{a} = $a; | |
514 | \& $b->{b} = $a->[1]; | |
515 | \& $b->{c} = $a->[2]; | |
516 | \& print Data::Dumper->Dump([$a,$b,$c], [qw(a b c)]); | |
517 | .Ve | |
518 | .PP | |
519 | .Vb 3 | |
520 | \& $Data::Dumper::Purity = 1; # fill in the holes for eval | |
521 | \& print Data::Dumper->Dump([$a, $b], [qw(*a b)]); # print as @a | |
522 | \& print Data::Dumper->Dump([$b, $a], [qw(*b a)]); # print as %b | |
523 | .Ve | |
524 | .PP | |
525 | .Vb 2 | |
526 | \& $Data::Dumper::Deepcopy = 1; # avoid cross-refs | |
527 | \& print Data::Dumper->Dump([$b, $a], [qw(*b a)]); | |
528 | .Ve | |
529 | .PP | |
530 | .Vb 2 | |
531 | \& $Data::Dumper::Purity = 0; # avoid cross-refs | |
532 | \& print Data::Dumper->Dump([$b, $a], [qw(*b a)]); | |
533 | .Ve | |
534 | .PP | |
535 | .Vb 3 | |
536 | \& ######## | |
537 | \& # deep structures | |
538 | \& ######## | |
539 | .Ve | |
540 | .PP | |
541 | .Vb 7 | |
542 | \& $a = "pearl"; | |
543 | \& $b = [ $a ]; | |
544 | \& $c = { 'b' => $b }; | |
545 | \& $d = [ $c ]; | |
546 | \& $e = { 'd' => $d }; | |
547 | \& $f = { 'e' => $e }; | |
548 | \& print Data::Dumper->Dump([$f], [qw(f)]); | |
549 | .Ve | |
550 | .PP | |
551 | .Vb 2 | |
552 | \& $Data::Dumper::Maxdepth = 3; # no deeper than 3 refs down | |
553 | \& print Data::Dumper->Dump([$f], [qw(f)]); | |
554 | .Ve | |
555 | .PP | |
556 | .Vb 3 | |
557 | \& ######## | |
558 | \& # object-oriented usage | |
559 | \& ######## | |
560 | .Ve | |
561 | .PP | |
562 | .Vb 6 | |
563 | \& $d = Data::Dumper->new([$a,$b], [qw(a b)]); | |
564 | \& $d->Seen({'*c' => $c}); # stash a ref without printing it | |
565 | \& $d->Indent(3); | |
566 | \& print $d->Dump; | |
567 | \& $d->Reset->Purity(0); # empty the seen cache | |
568 | \& print join "----\en", $d->Dump; | |
569 | .Ve | |
570 | .PP | |
571 | .Vb 3 | |
572 | \& ######## | |
573 | \& # persistence | |
574 | \& ######## | |
575 | .Ve | |
576 | .PP | |
577 | .Vb 8 | |
578 | \& package Foo; | |
579 | \& sub new { bless { state => 'awake' }, shift } | |
580 | \& sub Freeze { | |
581 | \& my $s = shift; | |
582 | \& print STDERR "preparing to sleep\en"; | |
583 | \& $s->{state} = 'asleep'; | |
584 | \& return bless $s, 'Foo::ZZZ'; | |
585 | \& } | |
586 | .Ve | |
587 | .PP | |
588 | .Vb 7 | |
589 | \& package Foo::ZZZ; | |
590 | \& sub Thaw { | |
591 | \& my $s = shift; | |
592 | \& print STDERR "waking up\en"; | |
593 | \& $s->{state} = 'awake'; | |
594 | \& return bless $s, 'Foo'; | |
595 | \& } | |
596 | .Ve | |
597 | .PP | |
598 | .Vb 10 | |
599 | \& package Foo; | |
600 | \& use Data::Dumper; | |
601 | \& $a = Foo->new; | |
602 | \& $b = Data::Dumper->new([$a], ['c']); | |
603 | \& $b->Freezer('Freeze'); | |
604 | \& $b->Toaster('Thaw'); | |
605 | \& $c = $b->Dump; | |
606 | \& print $c; | |
607 | \& $d = eval $c; | |
608 | \& print Data::Dumper->Dump([$d], ['d']); | |
609 | .Ve | |
610 | .PP | |
611 | .Vb 3 | |
612 | \& ######## | |
613 | \& # symbol substitution (useful for recreating CODE refs) | |
614 | \& ######## | |
615 | .Ve | |
616 | .PP | |
617 | .Vb 6 | |
618 | \& sub foo { print "foo speaking\en" } | |
619 | \& *other = \e&foo; | |
620 | \& $bar = [ \e&other ]; | |
621 | \& $d = Data::Dumper->new([\e&other,$bar],['*other','bar']); | |
622 | \& $d->Seen({ '*foo' => \e&foo }); | |
623 | \& print $d->Dump; | |
624 | .Ve | |
625 | .PP | |
626 | .Vb 3 | |
627 | \& ######## | |
628 | \& # sorting and filtering hash keys | |
629 | \& ######## | |
630 | .Ve | |
631 | .PP | |
632 | .Vb 5 | |
633 | \& $Data::Dumper::Sortkeys = \e&my_filter; | |
634 | \& my $foo = { map { (ord, "$_$_$_") } 'I'..'Q' }; | |
635 | \& my $bar = { %$foo }; | |
636 | \& my $baz = { reverse %$foo }; | |
637 | \& print Dumper [ $foo, $bar, $baz ]; | |
638 | .Ve | |
639 | .PP | |
640 | .Vb 13 | |
641 | \& sub my_filter { | |
642 | \& my ($hash) = @_; | |
643 | \& # return an array ref containing the hash keys to dump | |
644 | \& # in the order that you want them to be dumped | |
645 | \& return [ | |
646 | \& # Sort the keys of %$foo in reverse numeric order | |
647 | \& $hash eq $foo ? (sort {$b <=> $a} keys %$hash) : | |
648 | \& # Only dump the odd number keys of %$bar | |
649 | \& $hash eq $bar ? (grep {$_ % 2} keys %$hash) : | |
650 | \& # Sort keys in default order for all other hashes | |
651 | \& (sort keys %$hash) | |
652 | \& ]; | |
653 | \& } | |
654 | .Ve | |
655 | .SH "BUGS" | |
656 | .IX Header "BUGS" | |
657 | Due to limitations of Perl subroutine call semantics, you cannot pass an | |
658 | array or hash. Prepend it with a \f(CW\*(C`\e\*(C'\fR to pass its reference instead. This | |
659 | will be remedied in time, now that Perl has subroutine prototypes. | |
660 | For now, you need to use the extended usage form, and prepend the | |
661 | name with a \f(CW\*(C`*\*(C'\fR to output it as a hash or array. | |
662 | .PP | |
663 | \&\f(CW\*(C`Data::Dumper\*(C'\fR cheats with \s-1CODE\s0 references. If a code reference is | |
664 | encountered in the structure being processed (and if you haven't set | |
665 | the \f(CW\*(C`Deparse\*(C'\fR flag), an anonymous subroutine that | |
666 | contains the string '\*(L"\s-1DUMMY\s0\*(R"' will be inserted in its place, and a warning | |
667 | will be printed if \f(CW\*(C`Purity\*(C'\fR is set. You can \f(CW\*(C`eval\*(C'\fR the result, but bear | |
668 | in mind that the anonymous sub that gets created is just a placeholder. | |
669 | Someday, perl will have a switch to cache-on-demand the string | |
670 | representation of a compiled piece of code, I hope. If you have prior | |
671 | knowledge of all the code refs that your data structures are likely | |
672 | to have, you can use the \f(CW\*(C`Seen\*(C'\fR method to pre-seed the internal reference | |
673 | table and make the dumped output point to them, instead. See \*(L"\s-1EXAMPLES\s0\*(R" | |
674 | above. | |
675 | .PP | |
676 | The \f(CW\*(C`Useqq\*(C'\fR and \f(CW\*(C`Deparse\*(C'\fR flags makes \fIDump()\fR run slower, since the | |
677 | \&\s-1XSUB\s0 implementation does not support them. | |
678 | .PP | |
679 | \&\s-1SCALAR\s0 objects have the weirdest looking \f(CW\*(C`bless\*(C'\fR workaround. | |
680 | .PP | |
681 | Pure Perl version of \f(CW\*(C`Data::Dumper\*(C'\fR escapes \s-1UTF\-8\s0 strings correctly | |
682 | only in Perl 5.8.0 and later. | |
683 | .Sh "\s-1NOTE\s0" | |
684 | .IX Subsection "NOTE" | |
685 | Starting from Perl 5.8.1 different runs of Perl will have different | |
686 | ordering of hash keys. The change was done for greater security, | |
687 | see \*(L"Algorithmic Complexity Attacks\*(R" in perlsec. This means that | |
688 | different runs of Perl will have different Data::Dumper outputs if | |
689 | the data contains hashes. If you need to have identical Data::Dumper | |
690 | outputs from different runs of Perl, use the environment variable | |
691 | \&\s-1PERL_HASH_SEED\s0, see \*(L"\s-1PERL_HASH_SEED\s0\*(R" in perlrun. Using this restores | |
692 | the old (platform\-specific) ordering: an even prettier solution might | |
693 | be to use the \f(CW\*(C`Sortkeys\*(C'\fR filter of Data::Dumper. | |
694 | .SH "AUTHOR" | |
695 | .IX Header "AUTHOR" | |
696 | Gurusamy Sarathy gsar@activestate.com | |
697 | .PP | |
698 | Copyright (c) 1996\-98 Gurusamy Sarathy. All rights reserved. | |
699 | This program is free software; you can redistribute it and/or | |
700 | modify it under the same terms as Perl itself. | |
701 | .SH "VERSION" | |
702 | .IX Header "VERSION" | |
703 | Version 2.121 (Aug 24 2003) | |
704 | .SH "SEE ALSO" | |
705 | .IX Header "SEE ALSO" | |
706 | \&\fIperl\fR\|(1) |