I have some UTF-8 encoded strings in structures which I am dumping for debugging purposes with Data::Dumper.
A small test case is:
use utf8;
use Data::Dumper;
say Dumper({да=>"не"}
It outputs
{
"\x{434}\x{430}" => "\x{43d}\x{435}"
};
but I want to see
{
"да" => "не"
};
Of course my structure is quite more complex.
How can I make the strings in the dumped structure readable while debugging? Maybe I have to process the output via chr
somehow before warn/say
?
Just for debugging:
#!/usr/bin/perl
use strict;
use warnings;
use v5.10;
use utf8;
use Data::Dumper;
binmode STDOUT, ':utf8';
CASE_1: {
# Redefine Data::Dumper::qquote() to do nothing
no warnings 'redefine';
local *Data::Dumper::qquote = sub { qq["${\(shift)}"] };
# Use the Pure Perl implementation of Dumper
local $Data::Dumper::Useperl = 1;
say Dumper({да=>"не"});
}
CASE_2: {
# Use YAML instead
use YAML;
say Dump({да=>"не"});
}
CASE_3: {
# Evalulate whole dumped string
no strict 'vars';
local $Data::Dumper::Terse = 1;
my $var = Dumper({да=>"не"});
say eval "qq#$var#" or die $@;
}
__END__
$VAR1 = {
"да" => "не"
};
---
да: не
{
"да" => "не"
}
print Dumper(%mydata) =~ s/\\x\{([0-9a-f]{2,})\}/chr hex $1/ger;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With