Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello Monks,

I am struggling to make either of Data::Dump or Data::Dumper to print rendered(?) unicode characters rather than those ugly escapes but I can't seem to succeed. Perl prints them nicely but dump and dumper escape.

use utf8; binmode STDOUT, ':encoding(UTF-8)'; use Data::Dumper; use Data::Dump qw/pp/; my $pv = {'&#945;&#946;&#947;' => '&#967;&#968;&#950;'}; #<<<proper gr +eek key and value print pp($pv)."\n"; print Dumper($pv); print "XX:'".$pv->{'&#945;&#946;&#947;'}."'\n"; # proper greek nicely +printed # madness: { "\x{3B1}\x{3B2}\x{3B3}" => "\x{3C7}\x{3C8}\x{3B6}" } $VAR1 = { "\x{3b1}\x{3b2}\x{3b3}" => "\x{3c7}\x{3c8}\x{3b6}" }; # nicely printed XX:'&#967;&#968;&#950;' #<<<< that's proper greek

thanks, bliako

Edit: sorry, I did not mention JSON (thanks haukex for reminding me). What I am trying to do is to visualise a long JSON by converting it to a Perl var and then possibly edit the perl var, and finally save back to JSON (with the changes). So, yes, actually I am serialising and de-serialising but I can't seem to find an ascii-text-based, unicode-friendly serialiser other than Dump and Dumper. And for me, YAML is too tiring with all that spaces. Or I am just used to nested Perl data.

So, the input and output are JSON. Long JSON with unicode. I want to edit that JSON too. But it's too cumbersome in a text-based editor. And so I prefer to covert JSON to Perl, edit the Perl and then convert back to JSON. My procedure/tool was working until some unicode broke it.

In reply to Convert JSON to Perl and back with unicode by bliako

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (7)
    As of 2020-07-06 12:23 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found