Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: UTF8 with YAML or JSON

by zwon (Abbot)
on Jun 29, 2012 at 17:29 UTC ( #979156=note: print w/replies, xml ) Need Help??

in reply to UTF8 with YAML or JSON

Generally, if your code contains UTF-8 characters you should add use utf8 pragma (or encoding), otherwise you should call it not ă, but ă.

Replies are listed 'Best First'.
Re^2: UTF8 with YAML or JSON
by SBECK (Hermit) on Jun 29, 2012 at 17:36 UTC

    The 'use utf8' pragma is actually included in my module (though I omitted it from the simple code I posted here). However, I've played with it quite a bit and never got the results I wanted either.

    In the code posted here, the variable $in DOES contain UTF8 characters, but when you pass it to Load (which is obviously outside the scope of anything in this script) it gets converted. For that reason, though technically correct, I don't think that adding the pragma here will have any impact. If I'm wrong though, I'm certainly open to correction. I"m definitely not a UTF8 expert.

      never got the results I wanted either

      So do you actually want \x{c4}\x{83} as YAML::Syck returns to you, or you want \x{103}?

        I want the characters included in the data structure to be EXACTLY what I included in the text that got parsed. So, if I send in a string which contains a scalar of UTF8 values, then I should see UTF8 values in the data structure. YAML::Syck does this. YAML/YAML::XS/JSON/JSON::XS all take the scalars with UTF8 values in them and produce data structures containin perl encodings.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979156]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2018-06-19 01:03 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.