1. Perl
  2. Module
  3. here

Data::Dumper - Dump data

With the Data::Dumper module, hashes and arrays You can output the contents of variable such as in an easy-to-read format. You can also output complex data structures using reference in an easy-to-read way.

use Data::Dumper;

# Dump data
my $dump_string = Dumper $data;

You can use the Dumper function to convert the data into an easy-to-read string. Note that the Dumper function produces no output.

If you want to output to the screen, combine it with print function or warn function increase.

print Dumper $data;

warn Dumper $data;

Here are some examples of Data::Dumper.

Output a scalar variable

Scalar variable is output.

my $name = 'kimoto';
print Dumper $name;

Output array

Pass an array reference as an argument to Dumper.

my @nums = (1, 2, 3);
print Dumper \@nums;

Output array reference

print Dumper [1, 2, 3];

Output hash

Pass a hash reference as an argument to Dumper.

my %score = (math => 97, english => 80);
print Dumper \%score;

Output hash reference

print Dumper {math => 97, english => 80};

Data::Dumper FAQ

Q. When I output Japanese with Data::Dumper, it sometimes looks like a hexadecimal symbol instead of Japanese. Is there a solution?

A. It's happening because you're trying to output an decoded string (* 1). The output string must be a byte string, not an decoded string. However, I find it difficult to convert all strings contained in hashes and arrays to byte strings. Data::Recursive::Encode.pm There is module on CPAN, so I think it's a good idea to use it in combination with Data::Dumper.

* 1 For the decoded string and byte string, see Explanation of Encode module.

Related Informatrion