.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Data::Dump 3" .TH Data::Dump 3 2024-09-01 "perl v5.40.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Data::Dump \- Pretty printing of data structures .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Data::Dump qw(dump); \& \& $str = dump(@list); \& @copy_of_list = eval $str; \& \& # or use it for easy debug printout \& use Data::Dump; dd localtime; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module provides a few functions that traverse their argument list and return a string containing Perl code that, when \f(CW\*(C`eval\*(C'\fRed, produces a deep copy of the original arguments. .PP The main feature of the module is that it strives to produce output that is easy to read. Example: .PP .Vb 2 \& @a = (1, [2, 3], {4 => 5}); \& dump(@a); .Ve .PP Produces: .PP .Vb 1 \& "(1, [2, 3], { 4 => 5 })" .Ve .PP If you dump just a little data, it is output on a single line. If you dump data that is more complex or there is a lot of it, line breaks are automatically added to keep it easy to read. .PP The following functions are provided (only the dd* functions are exported by default): .IP "dump( ... )" 4 .IX Item "dump( ... )" .PD 0 .IP "pp( ... )" 4 .IX Item "pp( ... )" .PD Returns a string containing a Perl expression. If you pass this string to Perl's built-in \fBeval()\fR function it should return a copy of the arguments you passed to \fBdump()\fR. .Sp If you call the function with multiple arguments then the output will be wrapped in parenthesis "( ..., ... )". If you call the function with a single argument the output will not have the wrapping. If you call the function with a single scalar (non-reference) argument it will just return the scalar quoted if needed, but never break it into multiple lines. If you pass multiple arguments or references to arrays of hashes then the return value might contain line breaks to format it for easier reading. The returned string will never be "\en" terminated, even if contains multiple lines. This allows code like this to place the semicolon in the expected place: .Sp .Vb 1 \& print \*(Aq$obj = \*(Aq, dump($obj), ";\en"; .Ve .Sp If \fBdump()\fR is called in void context, then the dump is printed on STDERR and then "\en" terminated. You might find this useful for quick debug printouts, but the dd*() functions might be better alternatives for this. .Sp There is no difference between \fBdump()\fR and \fBpp()\fR, except that \fBdump()\fR shares its name with a not-so-useful perl builtin. Because of this some might want to avoid using that name. .ie n .IP "quote( $string )" 4 .el .IP "quote( \f(CW$string\fR )" 4 .IX Item "quote( $string )" Returns a quoted version of the provided string. .Sp It differs from \f(CWdump($string)\fR in that it will quote even numbers and not try to come up with clever expressions that might shorten the output. If a non-scalar argument is provided then it's just stringified instead of traversed. .IP "dd( ... )" 4 .IX Item "dd( ... )" .PD 0 .IP "ddx( ... )" 4 .IX Item "ddx( ... )" .PD These functions will call \fBdump()\fR on their argument and print the result to STDOUT (actually, it's the currently selected output handle, but STDOUT is the default for that). .Sp The difference between them is only that \fBddx()\fR will prefix the lines it prints with "# " and mark the first line with the file and line number where it was called. This is meant to be useful for debug printouts of state within programs. .IP "dumpf( ..., \e&filter )" 4 .IX Item "dumpf( ..., &filter )" Short hand for calling the \fBdump_filtered()\fR function of Data::Dump::Filtered. This works like \fBdump()\fR, but the last argument should be a filter callback function. As objects are visited the filter callback is invoked and it can modify how the objects are dumped. .SH CONFIGURATION .IX Header "CONFIGURATION" There are a few global variables that can be set to modify the output generated by the dump functions. It's wise to localize the setting of these. .ie n .IP $Data::Dump::INDENT 4 .el .IP \f(CW$Data::Dump::INDENT\fR 4 .IX Item "$Data::Dump::INDENT" This holds the string that's used for indenting multiline data structures. It's default value is " " (two spaces). Set it to "" to suppress indentation. Setting it to "| " makes for nice visuals even if the dump output then fails to be valid Perl. .ie n .IP $Data::Dump::TRY_BASE64 4 .el .IP \f(CW$Data::Dump::TRY_BASE64\fR 4 .IX Item "$Data::Dump::TRY_BASE64" How long must a binary string be before we try to use the base64 encoding for the dump output. The default is 50. Set it to 0 to disable base64 dumps. .ie n .IP $Data::Dump::LINEWIDTH 4 .el .IP \f(CW$Data::Dump::LINEWIDTH\fR 4 .IX Item "$Data::Dump::LINEWIDTH" This controls how wide the string should before we add a line break. The default is 60. .SH LIMITATIONS .IX Header "LIMITATIONS" Code references will be dumped as \f(CW\*(C`sub { ... }\*(C'\fR. Thus, \f(CW\*(C`eval\*(C'\fRing them will not reproduce the original routine. The \f(CW\*(C`...\*(C'\fR\-operator used will also require perl\-5.12 or better to be evaled. .PP If you forget to explicitly import the \f(CW\*(C`dump\*(C'\fR function, your code will core dump. That's because you just called the builtin \f(CW\*(C`dump\*(C'\fR function by accident, which intentionally dumps core. Because of this you can also import the same function as \f(CW\*(C`pp\*(C'\fR, mnemonic for "pretty-print". .SH HISTORY .IX Header "HISTORY" The \f(CW\*(C`Data::Dump\*(C'\fR module grew out of frustration with Sarathy's in-most-cases-excellent \f(CW\*(C`Data::Dumper\*(C'\fR. Basic ideas and some code are shared with Sarathy's module. .PP The \f(CW\*(C`Data::Dump\*(C'\fR module provides a much simpler interface than \&\f(CW\*(C`Data::Dumper\*(C'\fR. No OO interface is available and there are fewer configuration options to worry about. The other benefit is that the dump produced does not try to set any variables. It only returns what is needed to produce a copy of the arguments. This means that \f(CWdump("foo")\fR simply returns \f(CW\*(Aq"foo"\*(Aq\fR, and \f(CWdump(1..3)\fR simply returns \f(CW\*(Aq(1, 2, 3)\*(Aq\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" Data::Dump::Filtered, Data::Dump::Trace, Data::Dumper, JSON, Storable .SH AUTHORS .IX Header "AUTHORS" The \f(CW\*(C`Data::Dump\*(C'\fR module is written by Gisle Aas , based on \f(CW\*(C`Data::Dumper\*(C'\fR by Gurusamy Sarathy . .PP .Vb 2 \& Copyright 1998\-2010 Gisle Aas. \& Copyright 1996\-1998 Gurusamy Sarathy. .Ve .PP This distribution is currenly maintained by Breno G. de Oliveira. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.